Open this example in the interactive library
Source code
const n = 17,
groups = 4;
console.log(
Array.from(
{ length: groups },
(_, i) => Math.floor(n / groups) + (i < n % groups ? 1 : 0),
),
);
Sample output
[ 5, 4, 4, 4 ]

Open this example in the interactive library
const n = 17,
groups = 4;
console.log(
Array.from(
{ length: groups },
(_, i) => Math.floor(n / groups) + (i < n % groups ? 1 : 0),
),
);
[ 5, 4, 4, 4 ]