Advertisement
akaiiro

Recursive Onion

May 22nd, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.27 KB | None | 0 0
  1. def peel(vegetable_with_layers)
  2.   if vegetable_with_layers[0] == 'core'
  3.     # base case: have I reached the core?
  4.     vegetable_with_layers[0]
  5.   else
  6.     # not the core... remove one layer
  7.     peel(vegetable_with_layers[0])
  8.   end
  9. end
  10.  
  11. onion = [[['core']]]
  12. peel(onion)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement