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 passed the tests with JavaScript using code that will return 5 for this array..arr = [5, "5"]. Should return undefined. Need better tests. Needs to be fixed. Refactored my solution.
Nice!
This is the best answer!
Fixed
This task is extremilty usefull for JS developers it opens a lot of important featrues. Great Job.
Thank you.
PS. It was nice to find that
NaN != NaN // true
.Don't use HTML formatting in
Test.describe
/Test.it
headers.(y)
Some useful links: .replace(), ternary operator, comma operator, arrow functions.
match => (matches++, matches % n ? match : newValue)
is executed for everynew RegExp(oldValue, "g")
match.( (matches++), (matches % n ? match : newValue) )
, so operands are evaluated from the left to the right and the last operand is returned.matches++
increments our occurrences counter; now we have the current occurrence number.(matches % n) ? match : newValue
expression uses ternary operator. If occurrence number fits with nth rule - change it tonewValue
, otherwise leftmatch
untouched by returning itself.Note: using comma operator in a production code considered as a bad practice unless other is defined by team/company rules.
The way of avoiding comma operator in here is replacing
matches++, matches % n ? match : newValue
with++matches % n ? match : newValue
, which is also a kind of bad practice. Incrementing value should take own separate line of code.could you explain me your code with a little more details?
This comment is hidden because it contains spoiler information about the solution
Figured out, thank you for the interesting kata!
Chances are your function modified the array passed in when checking whether the elements are in order.
Numbers are not in order, but Random Test expecting true:
Thanks for noticing, the description has been updated.
null isn't an array. Kind've annoying to have to make an exception for a wrong parameter being passed.
Edit: Ah, I see it in the 'Should Return' portion now. It's a little unclear with it being left out of the instructions.
Loading more items...