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.
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?