Return Largest Numbers in Arrays passed using reduce method?


To get largest numbers passed using reduce(), use the Math.max() function. Following is the code −

const getBiggestNumberFromArraysPassed = allArrays => allArrays.reduce(
(maxValue, maxCurrent) => maxValue.push(Math.max(...maxCurrent)),maxValue),[]);
console.log(getBiggestNumberFromArraysPassed([[45,78,3,1],[50,34,90,89],[32,10,90,99]]));

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo94.js

Output

This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo94.js
[ 78, 90, 99 ]

Updated on: 07-Sep-2020

127 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements