Too Many Arguments in JavaScript
How many are too many?
In the short example below, JavaScript engine is complaining about too many arguments to Math.max()
.
It seems there is an upper limit for the number of arguments you can pass to a function.
The consequences of applying a function with too many arguments (that is, more than tens of thousands of arguments) varies across engines. (The JavaScriptCore engine has hard-coded argument limit of 65536.
Here is a safe way to calculate the maximum value in an array.
const max = arr.reduce((max, v) => Math.max(max, v), 0);