DEV Community

loading...

Discussion on: Mastering Hard Parts of JavaScript: Callbacks I

Collapse
semigradsky profile image
Dmitry Semigradsky

Current reduce implementation is wrong - it will handle first item twice if you will not set initialValue.

Collapse
internettradie profile image
Ryan Ameri Author

Thanks for picking that up! Should be fixed now 😀

Collapse
semigradsky profile image
Dmitry Semigradsky

if (Object.keys(arguments).length > 2) {

I think you can just use arguments.length. Cheers!

Thread Thread
deryckhenson profile image
Deryck Henson

better yet, typeof initialValue !== 'undefined' so you avoid touching arguments at all

Thread Thread
semigradsky profile image
Dmitry Semigradsky

initialValue can be undefined

Thread Thread
deryckhenson profile image
Deryck Henson

yes...but accum = initialValue loses its purpose if it is.