Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function arraySplitter(array, ...predicates) {
- const fnsLength = predicates.length;
- return array.reduce(reducer, Array(fnsLength + 1).fill(1).map(x => []))
- function reducer(state, item) {
- const index = predicates.findIndex(fn => fn(item));
- if (index > -1) {
- state[index].push(item);
- } else {
- state[fnsLength].push(item)
- }
- return state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement