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.
ohh god im sooo stupid
I was thinking the same thing... I think that it's because: "Your reducer function's returned value is assigned to the accumulator, whose value is remembered across each iteration throughout the array, and ultimately becomes the final, single resulting value." So, even though
prev
is never explictly reassigned, each time it hitsreturn
whatever is returned there is assigned toprev
for the next time it iterates through the array.Oh, never mind. I see that there is an initial value of an empty string supplied. Very cool!
Is this true? I don't see how this bit handles the first element in a long list. Since reduce() is not given an initial value, doesn't it start with an index value of 1? From MDN (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce): The index of the current element being processed in the array. Starts from index 0 if an initialValue is provided. Otherwise, it starts from index 1.
in first iteration PREV = "" and concatinate to ', ' + name
Why comma don't appear in start of string while first concatenation ?
Beautiful use of the reduce function. I certainly didn't think to use it to build the string!
This comment is hidden because it contains spoiler information about the solution
I love the reduce method, We can do a lot of things with it.
I would prefer to use object destructuring and replace current with { name } and all current.name's with name
I would prefer to use object destructing and replace current with { name } and all current.name's with name
This comment is hidden because it contains spoiler information about the solution
Oh my this is a great use of reduce. Most wouldnt think to use it to create a string.
I was taught that its best practice to use else if/else over ternary operators, as else if/else are easier to read.
This comment is hidden because it contains spoiler information about the solution
Thanks for the clean code! The parameter names you chose really helped me further my understanding of reduce! What a bad ass higher order function!
Loading more items...