-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test added #923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test added #923
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,17 +7,16 @@ | |
| * @returns {number[]} | ||
| */ | ||
| function splitInteger(value, numberOfParts) { | ||
| const parts = []; | ||
| let rest = value; | ||
| const base = Math.floor(value / numberOfParts); | ||
| const remainder = value % numberOfParts; | ||
|
|
||
| for (let partsLeft = numberOfParts; partsLeft > 0; partsLeft--) { | ||
| const part = Math.floor(rest / partsLeft); | ||
| const parts = new Array(numberOfParts).fill(base); | ||
|
|
||
| parts.push(part); | ||
| rest -= part; | ||
| for (let i = numberOfParts - remainder; i < numberOfParts; i++) { | ||
| parts[i] += 1; | ||
|
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: The remainder is currently being distributed to the last elements of the array (from index According to the requirements, the remainder should be distributed to the first elements (from index |
||
| } | ||
|
|
||
| return parts; | ||
| return parts.sort((a, b) => a - b); | ||
| } | ||
|
|
||
| module.exports = splitInteger; | ||
| module.exports = splitInteger; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: The loop currently distributes the remainder to the last
remainderelements. To ensure the difference between the largest and smallest parts is minimized, the remainder should be distributed to the firstremainderelements instead. Consider adjusting the loop to iterate from0toremainder - 1.