Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Last active December 17, 2015 04:39
Show Gist options
  • Select an option

  • Save mjhea0/5552375 to your computer and use it in GitHub Desktop.

Select an option

Save mjhea0/5552375 to your computer and use it in GitHub Desktop.
reverse an array the hard way, using push and pop
def reverse_an_array_the_hard_way(array)
new_array = []
length = array.length
for x in (1..length)
new_array << array.pop
end
p new_array
end
array = [1,2,3,4,5]
reverse_an_array_the_hard_way(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment