Algorithms and Data Structures · Junior · Question 60 of 75

Why can Math.max(...arr) fail on a very large array?

Explanation

Arguments are placed on the stack, so hundreds of thousands of them can throw a RangeError. For big arrays use a simple loop or reduce, which also stays O(n).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 60

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz