Created
April 15, 2022 07:25
-
-
Save damdafayton/0a4d9db6dde4908535f66a9b0c141365 to your computer and use it in GitHub Desktop.
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
/* | |
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. | |
https://www.hackerrank.com/challenges/mini-max-sum/problem?isFullScreen=true | |
*/ | |
function miniMaxSum(arr) { | |
// Write your code here | |
let min=arr[0], max=arr[0]; | |
arr.forEach((num,i)=>{ | |
min = Math.min(arr[i],min) | |
// console.log(min,arr[i] ) | |
max = Math.max(arr[i],max) | |
}) | |
let all = arr.reduce((sum,prev)=>sum+prev) | |
console.log(all-max, all-min) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment