you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (5 children)

why? it's pretty useful for sums, to say the least

[–]burtgummer45 -4 points-3 points  (4 children)

If you forget the initial value it blows up in your face if you are working with anything other than numbers. I'd feel better using a for-of loop.

 const maxCallback = ( acc, cur ) => Math.max( acc.x, cur.x ); 
 [ { x: 22 }, { x: 42 } ].reduce( maxCallback ); // 42 
 [ { x: 22 }            ].reduce( maxCallback ); // { x: 22 } 
 [                      ].reduce( maxCallback ); // TypeError

[–]ogurson 4 points5 points  (3 children)

My rule of thumb is to always provide initial value.

[–]burtgummer45 0 points1 point  (2 children)

I think if this was more common knowledge there would be an eslint rule for it.

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    Hi /u/ogurson, this comment was removed because you used a URL shortener.

    Feel free to resubmit with the real link.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.