I want to split an array into pairs of arrays.
var arr = [2, 3, 4, 5, 6, 4, 3, 5, 5]
would be
var newarr = [ [2, 3],
const items = [1, 2, 3, 4, 5]; const createBucket = (bucketItems, bucketSize) => buckets => { return bucketItems.length === 0 ? buckets : [...buckets, bucketItems.splice(0, bucketSize)]; }; const bucketWithItems = items.reduce(createBucket([...items], 4), []);