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.
.
yes, this is how it's supposed to work :)
Well, cheesing the kata in unexpected ways is also fun! So there are no problems with that.
The only problen I can think of is that it might be too obvious.
Well, it shows why one shouldn't do too much performance tuning in JS, it's somewhat magical! :P
But yeah, if a correct approach is used the total runtime (including the 6 seconds spent by the test code itself) should be less than 10-11 seconds.
If you're trying to get the keys of an object and looping through them for every array element that's going to be slow, because getting the keys of an object is slow. If you change the above to
It finishes in 8.5 seconds. This is a language feature, not a kata feature or algorithmic feature.
Also, in the end, this approach is still O(n^2), so I think you might as well drop this approach at once and think of a better algorithm :)
It's not.
You're looping through your histogram every loop, which, in general, will have O(n) entries (since duplicates are rare), so your algorithm is not O(n), but O(n^2).
That's the point, O(n^2) is not a fast enough algorithm for this kata.
Otherwise why'd you think this is 3kyu? :P
this is not an issue with the kata.