Here is one way to find the largest number in the given list of numbers using the built-in Math.max()
function and the Array.reduce()
method:
index.tsx170 chars6 lines
In the above code, we first define an array of numbers. Then, we use the reduce()
method to iterate over each value in the array and compare it with the previous value. At each step, we return the maximum of the two values using the Math.max()
function. Finally, the reduce()
method returns the largest number in the array. We assign this value to a variable called largestNumber
and log it to the console. The output shows that the largest number in the array is 5.
gistlibby LogSnag