Question 9
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const readings = new Array(5_000_000).fill(1);
readings[123] = 99;
console.log(Math.max(...readings));
- A It prints 99
- B It prints 1
- C RangeError: Maximum call stack size exceeded – five million arguments are too many; use reduce or a loop Correct
- D It prints Infinity
Correct Answer: Option C
Every element becomes a separate argument on the stack. readings.reduce((m, x) => (x > m ? x : m), -Infinity) works for any size.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!