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.
Seriously. The top 2 solutions above of this one is either 1) not readable or 2) not extensible.
I think it's too easy if you allow the usage of .sort
I would refrain from using single letter variables. It looks badass on paper, but if another programmer comes without knowing what the function is intended to do, he's going to want to murder you. Instead of writing "d" and "i", you should write out what they are. d => number, i => index. I know the kata gives you n and p, but code quality drops dramatically if you follow their naming of variable and try to look l33t with those single letter variables.