finding the largest number in an array

I have some code im having trouble with if someone could give me an idea or an answer id be greatly in your debt.

function getLargestNumber(numbers) {


/ Do not modify code below this line /

const largestNumber = getLargestNumber([1, 9, 5]);
console.log(largestNumber, '<-- should be 9');

You are viewing a single comment. View All

In JavaScript, you can use the Math.max.apply() function to do this, like so:

This is like calling:

You can also do this with Math.min too.

Hope this is what you were looking for!


@LeonDoesCode In the future, please do not give direct answers. Instead, try to help them understand how to do it


@theangryepicbanana That is why I also included the second part (after "This is like calling:"). It explains what that function is similar to calling, and how that function works.

However, I see your point, will try to not do this in future. Thanks for the feedback!


@LeonDoesCode thank you i was over complicating this..i was trying to put in a for loop and everything lol


@DamienVapes Gald it helped!


@LeonDoesCode how did you post the code the way you did on your earlier like to show my repl completed here


@DamienVapes You can post code like so:

I recommend looking at this for more information.

However, if you want to post a Repl, it is recommended that you use the share Repl feature when you post the code (above the title).