deno.land / x / rambda@v9.1.1 / src / splitWhen.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export function splitWhen(predicate, input){ if (arguments.length === 1){ return _input => splitWhen(predicate, _input) } if (!input) throw new TypeError(`Cannot read property 'length' of ${ input }`)
const preFound = [] const postFound = [] let found = false let counter = -1
while (counter++ < input.length - 1){ if (found){ postFound.push(input[ counter ]) } else if (predicate(input[ counter ])){ postFound.push(input[ counter ]) found = true } else { preFound.push(input[ counter ]) } }
return [ preFound, postFound ]}
rambda

Version Info

Tagged at
2 months ago