Back

JS Fundamentals / Find Max in Array

00:00
1/20

Find Max in Array

Easy

Write a function findMax(arr) that takes an array of numbers and returns the largest number.

  • 1

    Initialize a max variable with the first element.

  • 2

    Iterate through the array.

  • 3

    If current element > max, update max.

  • 4

    Return max.

JAVASCRIPT PLAYGROUND
JAVASCRIPT PLAYGROUND
⏳ Loading editor…