Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions splitInteger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function splitInteger(value, numberOfParts) {
const base = Math.floor(value / numberOfParts);
const remainder = value % numberOfParts;

const result = new Array(numberOfParts - remainder).fill(base);
result.push(...new Array(remainder).fill(base + 1));

return result.sort((a, b) => a - b);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: The result is always sorted in ascending order before being returned. Unless the task or checklist explicitly requires the output to be sorted, this may be incorrect. Typically, the larger parts (base+1) should come first, followed by the smaller parts (base), preserving the original distribution order. Please verify the requirements and remove the .sort((a, b) => a - b) if sorting is not needed.

}

module.exports = splitInteger;
Loading