Skip to content

Instantly share code, notes, and snippets.

@mikrofusion
Created March 16, 2014 18:44
Show Gist options
  • Save mikrofusion/9587917 to your computer and use it in GitHub Desktop.
Save mikrofusion/9587917 to your computer and use it in GitHub Desktop.
reverse array (ruby)
#!/usr/bin/ruby
class Array
def reverse_recursive(arr)
if arr.length == 1 then return arr end
a = arr.shift
reverse_recursive(arr) << a
end
def reverse
reverse_recursive(self)
end
end
puts "original array: #{ARGV.inspect}"
puts "reversed array: #{ARGV.reverse.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment