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.
Fixed
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.This comment is hidden because it contains spoiler information about the solution
Figured out, thank you for the interesting kata!
Numbers are not in order, but Random Test expecting true:
Thanks for noticing, the description has been updated.
Pleased to hear :)
I'm glad you liked it :)
Thanks for helping!
^_^
.I think adjusting the description a bit by kata author would be helpful for other warriors.
This comment is hidden because it contains spoiler information about the solution
"In the case of duplicate alphabet letters, you have to arrange them according to the number that appeared first in the input string" - confused me.
Blocks like
"22y6"
not a numbers, so that sounds like subsorting by first number occurance in block is needed.It's a bit harder than other 8 kyu katas, imho.
This comment is hidden because it contains spoiler information about the solution