mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-09 11:09:07 +01: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;
|
|
}
|