Last active
August 29, 2015 14:01
-
-
Save Rojo/6d6ad947505fc917a72a to your computer and use it in GitHub Desktop.
A simple recursion example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def peel(vegetable_with_layers) | |
if vegetable_with_layers[0] == 'core' | |
# base case: have I reached the core? | |
vegetable_with_layers[0] | |
else | |
# not the core... remove one layer | |
peel(vegetable_with_layers[0]) | |
end | |
end | |
onion = [[['core']]] | |
peel(onion) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment