Created
February 7, 2021 11:45
-
-
Save AlaeddineMessadi/c1d040fd988e57f94db218dbc8c0d463 to your computer and use it in GitHub Desktop.
Split the number into N parts such that difference between the smallest and the largest part is minimum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var splitInteger = function(num, parts) { | |
const remainder = num % parts | |
const value = (num - remainder) / parts | |
return Array(parts).fill(value).fill(value + 1, 0, remainder); | |
} | |
console.log(splitInteger(25,5)) | |
// Input: X = 25, N = 5 | |
// Output: 5 5 5 5 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment