Était-ce utile?

Question

Return Largest Numbers in Arrays passed using reduce method?

JavascriptWeb DevelopmentObject Oriented Programming

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 ]
raja
Published on 07-Sep-2020 12:02:16
Advertisements
Était-ce utile?
Non affilié à Tutorialspoint
scroll top