Write a function called "spiral" that takes an NxM array as input and returns a "spiral" path through the array, starting in the upper-left corner and moving clockwise. Use the language of your choice.
For example (in Ruby), if
array = [[1,2,3],
[8,9,4],
[7,6,5]]
then
spiral(array) # => [1,2,3,4,5,6,7,8,9]
It should work on any NxM array, so don't assume the input is a square array. However, every row will have the same number of elements.
So there aren't any spoilers, if you decide to solve it please fork this gist and link to the fork in a comment. :)
Thanks for the helpful comments, @jfarmer. I've refactored my solution taking into account what you've said. Any other suggestions?