1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 19:19:07 +01:00
CodeWars/7kyu/distributing_candies_fairly/solution.js

21 lines
269 B
JavaScript
Raw Normal View History

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