session3/challenge/5_blocks.rb
# Write a method, spiral_access, that takes a 2d square array (an array of arrays)
# and a block, and calls the block for each of the elements, in spiral order.
#
# HINT: This method is probably best sovled recursively
#
# Example:
# two_d = [
#   [ 1,  2,  3,  4, 5],
#   [16, 17, 18, 19, 6],
#   [15, 24, 25, 20, 7],
#   [14, 23, 22, 21, 8],
#   [13, 12, 11, 10, 9],
# ]
# order = []
# spiral_access two_d do |i|
#   order << i
# end
# order # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
Write a method, spiral_access, that takes a 2d square array (an array of arrays)
and a block, and calls the block for each of the elements, in spiral order.

This method is probably best sovled recursively


Write a method spiral_access that takes a 2d square array ( an array of arrays ) and a block and calls the block for each of the elements in spiral order . This method is probably best sovled recursively
def spiral_access(arrays)
  i = 0
  arrays.each do |array|
    array.each do |element|
      if block_given?
        if element = i + 1
          yield element
          i += 1
        end
      end
    end
  end
end
def spiral_access ( arrays ) i = 0 arrays . each do | array | array . each do | element | if block_given? if element = i + 1 yield element i += 1 end end end end end
Write a method, spiral_access, that takes a 2d square array (an array of arrays)
and a block, and calls the block for each of the elements, in spiral order.
Write a method spiral_access that takes a 2d square array ( an array of arrays ) and a block and calls the block for each of the elements in spiral order .
arrays
<not_specific>