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 agree that they should not be creating a new object but simple regex and dictionaries should be understandable to any developer.
I did this and didn't work
@dansel I get your point, you can approach the kata in whichever way you want as long as it's not forbidden. But the problem is your solution is voted as best practice, which certainly isn't. That's why people protest.
I think it is not the best practice at all. On each symbol you create new object. Also, the algorithm itself not very understandable
Why it doesn't compile?
wow thinking out of the box, thats smart!
He calls the replace(). Replace accepts something called a regex (which tells your replace method to expect a certain type of string pattern -- in this case the regex is a '.' which ensures your input is any character but a line terminator). The second parameter replace accepts is a callback function. The callback function contains a dictionary of matching DNA values. This function runs on each individual character from the original dna string and 'replaces' it with the matching DNA value from the dictionary.
How does it work?
very elegant, however will be too slow given a couple of million array elements.
'filter' creates a new array + iterates through the total array.
the 'reduce' solution stops when needed and returns a boolean.
Thanks for your reply.
Since speed is not mentioned in the kata description I did not care about execution time.
It's a 7 kyu kata and it's "fast enough".
This solution is KISS and easy on the eyes though.
One could of course implement faster solutions with "fail fast".
Slow
This is a common trend in codewars. The most upvoted solutions tend to be shortest rather than the most efficient.
awesome
Using filter or forEach, while more succinct, is less efficient for this sort of thing, since these functions will continue until the entire array has been iterated, whereas a normal loop (or functions like every/some) can be broken as soon as an element is found that does not meet the criteria.
Loading more items...