发布于 5年前

js 数组项通过条件分组

const bifurcate = (arr, filter) => 
  arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []])

// EXAMPLES
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]) 
// [ ['beep', 'boop', 'bar'], ['foo'] ]
©2020 edoou.com   京ICP备16001874号-3