const bifurcate = (arr, filter) =>
        arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
      bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); 
      // [ ['beep', 'boop', 'bar'], ['foo'] ]
      

      Javascript language logo
      Split Array

      This snippet splits values into two groups and then puts a truthy element of filterin the first group, and in the second group otherwise.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.