Skip to content

Instantly share code, notes, and snippets.

@neos1803
Created March 17, 2022 07:36
Show Gist options
  • Save neos1803/2cd8e4d979d0f977914e2e036a594d09 to your computer and use it in GitHub Desktop.
Save neos1803/2cd8e4d979d0f977914e2e036a594d09 to your computer and use it in GitHub Desktop.
Function to return the minimum sum and maximum sum of an array
function minMaxSum(array = []) {
const sorted = array.sort((a, b) => a - b) // Ascended sort
const minSum = sorted.slice(0, array.length/2).reduce((p, c) => p+=c);
const maxSum = sorted.slice(array.length/2, array.length).reduce((p, c) => p+=c);
return [minSum, maxSum]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment