You are viewing a single comment's thread. Return to all comments →
function miniMaxSum(arr: number[]): void { // Write your code here const sortedArray = arr.sort(); const minSum = sortedArray.slice(0,sortedArray.length-1).reduce((acc,val) => acc + val, 0); const maxSum = sortedArray.slice(1).reduce((acc,val) => acc + val, 0); console.log(minSum, maxSum) }
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all comments →
function miniMaxSum(arr: number[]): void { // Write your code here const sortedArray = arr.sort(); const minSum = sortedArray.slice(0,sortedArray.length-1).reduce((acc,val) => acc + val, 0); const maxSum = sortedArray.slice(1).reduce((acc,val) => acc + val, 0); console.log(minSum, maxSum) }