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.
Looks clever to use just one loop for
toRoman
and bitwise XOR, as a hack get an integer numeral part, it could be replaced by|
as well. Also the second argument forrepeat
method allows to avoid usingreturn
statementIt's pretty well step to use regexp match into
fromRoman
, it may be simplified a bit torom.match(/CM|CD|XC|XL|IX|IV|\w/gi)
The perfect solution with
fromRoman
regexp, it's really clever to guess for it, as a good splitter for target roman numeral pairsIt seems that performance leaks are not issue for this purpose as any roman number can't extremelly big in reality. Cool approach, especially for
fromRoman
function. Unfortunatellysubstr
is already considered as deprecated, so it may be replacedm is the part of a string that's matched with regexp provided, the callback replaces this part with incremented value. For instance if there is 'somestring0' it returns ++0(1) and if it's 'somestring499' ++499(500) is returned. Then it replaces regexp in the way as joekotvas explained above
Say what?
This comment is hidden because it contains spoiler information about the solution