DEV Community

Discussion on: 1 line of code: How to split an Array in half

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited
const split = num => ([...arr]) => Array(num).fill(0)
   .map((_,i)=>Math.floor(arr.length/num)+(i<arr.length%num))
   .map(n => arr.splice(0, n))
Enter fullscreen mode Exit fullscreen mode