mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-09-08 01:26:57 +02:00
20 lines
269 B
JavaScript
20 lines
269 B
JavaScript
function distribute(m, n) {
|
|
if (n <= 0) {
|
|
return [];
|
|
}
|
|
|
|
let result = Array(n);
|
|
if (m <= 0) {
|
|
result.fill(0);
|
|
} else {
|
|
|
|
result.fill(Math.floor(m / n));
|
|
m %= n;
|
|
|
|
for (let i = 0; i < m; i++) {
|
|
result[i]++;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|