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.
I guess I'm far too late but still will reply for future reader.
The first argument to the reduce callback is "accumulator" which is a variable that is what was returned from the function on the previous run.
If it's the first run of the function then accumulator will contain a first element of the array or the user specified value.
For example we can sum everything in array via [1,2,3].reduce((a,x) => a+x) //this uses a fat arrow syntax, that is left as an excercise to the reader
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
We don't want to return the result of the
splice
but the value ofe
after the splice.See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator
Because sometimes we want to convert from one type to another.
I don't understand - "(e.splice(), e)". How does the coma work here? This is the first time I see sth returned as (function, e). I'm confused.
Can someone explain to me how does "return" work in reduce()? I don't understand how it could loop like this. Isn't "return" like "break;" in loops? Shoudn't it "break;" after first iteration?
Yep, I meant in Chrome's console. I didn't try it in other browser. Do you have any idea why my & your previous code did fail in codewars? Not for the sake of completing a challenge, I'm just curious :)
Your code also fails. I tested my & your code in Chrome & it works 100% right. I think sth is wrong with this Kata, not our code.
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
I don't know if some is trolling me or I don't understand sth, but those tests seem to be bugged. There are tests, which make ZERO SENSE like - Tests 0,1,0,0 & it expects 2 instead 4. I passed all initial tests, but in the other phase, I failed massivly & all the tests I failed seem to be broken.