siddhartharora02
4/12/2017 - 10:08 AM

Return Largest Numbers in Arrays

Return Largest Numbers in Arrays

function largestOfFour(arr) {
  var res = arr.map(innerArr=>{
    return innerArr.reduce((acc,val)=>{
      return (acc>val)?acc:val;
    })
  })
  return res; // res is an array of largest numbers from each array
  // to again find the largest number just apply reduce function
  res.reduce((acc,val)=>{
     return (acc>val)?acc:val;
  })
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);