Skip to main content
Module

x/rambda/splitAt.js

Faster and smaller alternative to Ramda
Go to Latest
File
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) ]}