Q:

Write a JavaScript program to split values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to

0

Write a JavaScript program to split values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const bifurcateBy = (arr, fn) =>
  arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
console.log(bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now