Skip to content

Commit e460000

Browse files
Update README.md
1 parent 3fd8d93 commit e460000

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ integer elements.
88
- The array should be sorted ascending (from lowest to highest)
99

1010
You don't need to validate arguments (they are always valid).
11-
1211
Examples:
1312

1413
```js
@@ -17,6 +16,24 @@ splitInteger(6, 2) === [3, 3]
1716
splitInteger(17, 4) === [4, 4, 4, 5]
1817
splitInteger(32, 6) === [5, 5, 5, 5, 6, 6]
1918
```
19+
function splitInteger(value, numberOfParts) {
20+
const base = Math.floor(value / numberOfParts);
21+
const remainder = value % numberOfParts;
22+
23+
const result = [];
24+
25+
for (let i = 0; i < numberOfParts - remainder; i++) {
26+
result.push(base);
27+
}
28+
29+
for (let i = 0; i < remainder; i++) {
30+
result.push(base + 1);
31+
}
32+
33+
return result;
34+
}
35+
36+
module.exports = splitInteger;
2037

2138
[Guideline](https://github.com/mate-academy/js_task-guideline/blob/master/README.md)
2239

0 commit comments

Comments
 (0)