Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript problems

/*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.*/

function miniMaxSum(arr) {
    
    let sumMin=0;
    let sumMax=0;
    for(let i=0;i<arr.length;i++){
        sumMin+=arr[i]
        sumMax+=arr[i]
    }
    let max = Math.max(...arr);
    let min = Math.min(...arr);
    
console.log(sumMin-max ,sumMax-min)
}
 
PREVIOUS NEXT
Tagged: #JavaScript #problems
ADD COMMENT
Topic
Name
9+9 =