Boil it down with reduce()
.reduce() walks the array carrying an accumulator, returning one final
value β a sum, a max, a joined string, anything.
[1, 2, 3].reduce((acc, n) => acc + n, 0); // 6
Your task
Write max that returns the largest number in a non-empty array. (You can use
reduce, Math.max, or a loop β only the result is graded.)
β‘ 35 XP
π§± Code blocks
Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.
solution.jsRuns in your browser
Loading editorβ¦
Tests3 to pass
max([1,5,3]) === 5
all negative
single item
Run your code to check these.