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.
Credit and inspiration for this exercise goes to Jesse Farmer.