Created
September 25, 2021 14:23
-
-
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
This file contains 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
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