Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Default User Avatar

    Why all those checks when you can do with just "array.length < 2" ;-)
    Anyway, I like the solution, mainly because of its recursive nature.

  • Default User Avatar

    Can someone elaborate what's going on there? (: It's a bit complicated.

  • Custom User Avatar

    haan, explain your meaning, please.

  • Custom User Avatar

    Thanks to you both! Of all my kata solutions, this is my favorite.