You are viewing a single comment's thread. Return to all comments →
function miniMaxSum(arr: number[]): void { let minValue = 0; let maxValue = 0; const sortedArray = arr.sort() if(sortedArray[0] === sortedArray[1]){ maxValue = minValue = sortedArray.splice(0, sortedArray.length - 1).reduce((a,b) => a+b, 0) console.log(`${minValue} ${maxValue}`) return } const maxFlag = sortedArray[arr.length - 1] const minFlag = sortedArray[0] minValue = sortedArray.filter((a)=> a !== maxFlag).reduce((a,b)=> a+b, 0) maxValue = sortedArray.filter((a)=> a !== minFlag).reduce((a,b)=> a+b, 0) console.log(`${minValue} ${maxValue}`) }
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 →