const split = (array, n) => array.reduce((a, c, i) => i % n == 0 ? [...a, [c]] : [...a.slice(0, -1), [...a[a.length - 1], c]], [])
- 例
split([1, 2, 3, 4], 2) // -> [[1, 2], [3, 4]]
- 参考元様
const split = (array, n) => array.reduce((a, c, i) => i % n == 0 ? [...a, [c]] : [...a.slice(0, -1), [...a[a.length - 1], c]], [])
split([1, 2, 3, 4], 2) // -> [[1, 2], [3, 4]]