I agree you could do the same with reduce if you’d prefer that. I prefer the shorter version, but that’s why it’s good there are many ways to do the same thing. I wouldn’t call JavaScript “insane” because it does some things differently.
In your example, you probably want to use Number.NEGATIVE_INFINITY instead of 0 as the initial value in case there are only negative values in the array.
In your example, you probably want to use Number.NEGATIVE_INFINITY instead of 0 as the initial value in case there are only negative values in the array.
You can just pass it a single argument. I tried that at first but changed it because I thought that was causing my error, but then I figured out it was actually reduce passing additional garbage to Math.max.
I wouldn’t call JavaScript “insane” because it does some things differently.
It's not that it does things differently that makes insane. It's the fact that it does things differently in insane ways. Passing random stuff nobody wanted to the combining function in reduce is one such thing, but there's many many more.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I agree you could do the same with
reduce
if you’d prefer that. I prefer the shorter version, but that’s why it’s good there are many ways to do the same thing. I wouldn’t call JavaScript “insane” because it does some things differently.In your example, you probably want to use Number.NEGATIVE_INFINITY instead of
0
as the initial value in case there are only negative values in the array.You can just pass it a single argument. I tried that at first but changed it because I thought that was causing my error, but then I figured out it was actually
reduce
passing additional garbage toMath.max
.It's not that it does things differently that makes insane. It's the fact that it does things differently in insane ways. Passing random stuff nobody wanted to the combining function in
reduce
is one such thing, but there's many many more.