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.
For example, if the array is [1, 3, 5, 7, 9]. Our minimum sum is 1 + 3 + 5 + 7 = 16 and our maximum sum is 3 + 5 + 7 + 9 = 24.
function miniMaxSum(arr) {
let max = arr.reduce((a, b) => a + b, 1);
let min = arr.reduce((a, b) => a + b, 0, arr.length - 1);
console.log(min, max);
}
Right now, the output should be 10, 14 if the array is just [1, 2, 3, 4, 5].
The output I am getting is 15, 16.
The max variable should just add everything starting from index 1 no?
And the min variable I'm not sure if you're able to do this, but my thinking was initialize the starting at index 0 and go up to the end of the array but minus 1 index.
How can I correct this?