function group(arr, step) { return arr.reduce((x, y) => { return Array.isArray(x) ? (x[x.length - 1].push(y) == step ? [...x, []] : x) : [[x, y]]; }) } group([1, 2, 3, 4, 5, 6, 7, 8, 9, 0],3)
function group(arr, step) { function copyPush(v, item) { var res = []; for (var i = 0; i < v.length; i++) { res.push(v[i]); } res.push(item); return res; } return arr.reduce(function(x, y){ return Array.isArray(x) ? (x[x.length - 1].push(y) == step ? copyPush(x,[]) : x) : [[x, y]]; }) } //group([1, 2, 3, 4, 5, 6, 7, 8, 9, 0],3)