Last active
December 17, 2015 04:39
-
-
Save mjhea0/5552375 to your computer and use it in GitHub Desktop.
reverse an array the hard way, using push and pop
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 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