JSFiddle - React, Tailwind, and code Playground

by Paweł Niemczyk

JavaScript

let array = [1,2,3,4,5,6,7,8,9,10];
let initialValue = [[],[]];
let filterFn = (val) => val > 2;

let result = array.reduce(function(prevVal, elem, index, array) {
	let arrayIndex = filterFn(elem) ? 0 : 1;
  prevVal[arrayIndex].push(elem);
  return prevVal;
}, initialValue);

console.log(result);