Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
using the initial value parameter for the reduce method is an elegant way of handling the empty array scenarios. Something new I've learn't today, thanks.
did not realize 0 mod 2 is 0. another little lesson, thanks!
"If the input array is empty consider it as: [0] (array with a zero)."
oddOrEven([]) return undefined
When no value is passed to
reduce()
, like ([]
), where the initial value is 0. The reduce returns it's initial value.it declares where the accumulator, in this case a is starting at :)
Happened to me in another kata, but I remember to add 'initialvalue' since then. Haha!
for 1 hour I was just staring at the code and didn't know how to solve my problem, now I see that it was only in adding the ",0" part in reduce. please let me cry.
exactly same here !!
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Could someone please explain how this checks if the array is empty? I'm guessing it's to do with passing the initial value of 0 to the reducer.
And I thought I was being clever, and same answer end up being the most implimented
I think it's better to format a little bit for readability
Loading more items...