Skip to content

Instantly share code, notes, and snippets.

@ciniglio
Created December 7, 2012 17:00
Show Gist options
  • Save ciniglio/4234664 to your computer and use it in GitHub Desktop.
Save ciniglio/4234664 to your computer and use it in GitHub Desktop.
Recursion
def lastindex(e, a)
return -1 if a.empty?
if a.pop == e
return a.length
end
return lastindex(e, a)
end
def sum(a)
return 0 if a.empty?
return a.shift + sum(a)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment