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 also thought of using a switch, but as you can see by the comments here, using switch(true) and then doing evaluations in each case is kind of an anti-pattern that can be hard to read and debug.
I would avoid and look for one of the other conditional options in this board.
i think var will make counter accessible via constructor, and there was no test for this case
To further clarify for those still confused on why passing in
switch(value)
doesn't work, it's because it's comparing a Boolean to a numerical one, which will always befalse
. Say our average is 95 and we're assigning that to a variableavg
. If we try to pass inavg
as the argument to the switch statement's parameter, this is essentially what is happening:(avg >= 90)
is returning a Boolean. We'll never reach a switch statement that evaluates to true if we're passing in ouravg
variable as the argument. I hope this helps!any source?
How does the instances have access to the
counter
variable? It's not passed as a method (e.gthis.counter
), it's not passed as a prototype either (e.gCounter.prototype.counter
).So how? Closure? That would make sense if we call it directly on the
Counter
function constructor, not its instances.Because we are looking for one of the case condition results to be true :) Like, we have 87 as avg, so case (avg >= 90) gives you false.. next gives you true, so it will be used.
why we need swith(true) not switch(value)? I just don't understand
You could also try the filter method or recursion to solve this :)
yeah, i thought about regex before anything, than i tried the for loop.
It's also good to expand on your knowledge and practice all methods of solving as well, regex being one of them even if they are slower :)
regex can be 87% slower than own implementation using for loop. shouldnt matter tho. gg
The instructions are a little unclear and should be elaborated.