1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 11:09:07 +01:00
CodeWars/7kyu/distributing_candies_fairly/solution.js
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

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;
}