UNPKG

rambdax

Version:

Extended version of Rambda - a lightweight, faster alternative to Ramda

22 lines (17 loc) 596 B
import { _isArray } from './_internals/_isArray' import { drop } from './drop' import { maybe } from './maybe' import { take } from './take' export function splitAt(index, input){ if (arguments.length === 1){ return _list => splitAt(index, _list) } if (!input) throw new TypeError(`Cannot read property 'slice' of ${ input }`) if (!_isArray(input) && typeof input !== 'string') return [ [], [] ] const correctIndex = maybe( index < 0, input.length + index < 0 ? 0 : input.length + index, index ) return [ take(correctIndex, input), drop(correctIndex, input) ] }