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.
He just used high level functions for the purpose of this kata, with a simple algorithm in mind:
1: Get first line in order (left to right), using shift on the matrix you get the first line.
2: Last column in order (top to bottom), using map in the matrix, poping the last elements from every line.
3: Last line reversed (right to left), using pop in the matrix you get the last array, and then reverse it (because of the snail logic).
4: first column reversed (bottom to up), you again go through the entire matrix (using map) getting the first element (using shift) of each array, and then reverse it, since the other elements are being removed it works.
Do it all over again until there is no more items.
Hope it's clear enough.
Well, it might be slower. But I think that for the purpose of his application it's good enough.
You can always spend more time trying to optimize things, but I think that in this case it is way clearer than to work with lots of indexes, increments or whatever (which was my case).
The simple use of high level functions with his simple algorithm in mind is enough until more performance is actually needed.
Not saying that measuring and comparing performance is not valid at all though.
Why all those checks when you can do with just "array.length < 2" ;-)
Anyway, I like the solution, mainly because of its recursive nature.
Can someone elaborate what's going on there? (: It's a bit complicated.
haan, explain your meaning, please.
Thanks to you both! Of all my kata solutions, this is my favorite.