Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. function arraySplitter(array, ...predicates) {
  2. const fnsLength = predicates.length;
  3. return array.reduce(reducer, Array(fnsLength + 1).fill(1).map(x => []))
  4.  
  5. function reducer(state, item) {
  6. const index = predicates.findIndex(fn => fn(item));
  7. if (index > -1) {
  8. state[index].push(item);
  9. } else {
  10. state[fnsLength].push(item)
  11. }
  12. return state;
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement