Skip to content

Find the largest number contained in a JavaScript array

To get the largest number in the array of numbers we can use the reduce() function to compare each number and return the largest.

var arrNum = [10, 5, 20, 15];
var max = arrNum.reduce(function(a,b){
	return (a > b) ? a : b;
console.log(max); //20
See also  Time Complexity: Primality - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.