Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Created September 25, 2021 14:23
Show Gist options
  • Save Stefanacef/3d1ca6fe39ba1529f7bbb929f0756b15 to your computer and use it in GitHub Desktop.
Save Stefanacef/3d1ca6fe39ba1529f7bbb929f0756b15 to your computer and use it in GitHub Desktop.
Find the minimum and maximum values that can be calculated by summing exactly four of the five integers | Solution | JavaScript
const arr = [7, 69, 2, 221, 8974];
function miniMaxSum(arr) {
let result=[]
arr = arr.sort((a, b) => {
return a - b;
});
result.push(arr.slice(0,4).reduce((acc,e)=>acc+e))
result.push(arr.reverse().slice(0,4).reduce((acc,e)=>acc+e))
console.log(...result)
}
miniMaxSum(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment