You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While 0 is the “nothing” value for addition (anything + 0 == anything), I really feel 1 is the “nothing” value for multiplication (anything × 1 == anything). I’m sure there’s some academic papers backing up my feelings. 😄
https://github.com/1-liners/1-liners/tree/master/documentation#product
Currently, it returns
1
. Shouldn't an empty array product be 0 not 1? After all, nothing from nothing leaves nothing. 0 * 0 = 0.It's easy to fix with a ternary check for length.
export default (array) => array.length ? array.reduce((a, b) => (a * b), 1) : 0;
https://www.youtube.com/watch?v=aj5DccgBYeM 😉
The text was updated successfully, but these errors were encountered: