Mini-Max Sum

  • + 0 comments

    Simple Javascript solution here, works by sorting the initial array and then reducing the first 4 indices, then last 4 indices to return the min and max sum

    function miniMaxSum(arr) { // Write your code here let sorted = [...arr.sort((a, b)=>{return a-b})]; console.log(sorted.slice(0, 4).reduce((a, b)=>{ return a+b }, 0), sorted.slice(1).reduce((a, b)=>{ return a+b }, 0)) }