Skip to content

Instantly share code, notes, and snippets.

@AlaeddineMessadi
Created February 7, 2021 11:45
Show Gist options
  • Save AlaeddineMessadi/c1d040fd988e57f94db218dbc8c0d463 to your computer and use it in GitHub Desktop.
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
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