rambdax
Version:
Extended version of Rambda - a lightweight, faster alternative to Ramda
29 lines (23 loc) • 692 B
JavaScript
import { isArray as isArrayMethod } from './_internals/isArray.js'
export function dropWhile(predicate, iterable){
if (arguments.length === 1){
return _iterable => dropWhile(predicate, _iterable)
}
const isArray = isArrayMethod(iterable)
if (!isArray && typeof iterable !== 'string'){
throw new Error('`iterable` is neither list nor a string')
}
const toReturn = []
let counter = 0
while (counter < iterable.length){
const item = iterable[ counter++ ]
if (!predicate(item)){
toReturn.push(item)
break
}
}
while (counter < iterable.length){
toReturn.push(iterable[ counter++ ])
}
return isArray ? toReturn : toReturn.join('')
}