Created
May 8, 2020 17:24
-
-
Save ajtran303/e69eedb5a16474e4a38927ebb3c6b11c to your computer and use it in GitHub Desktop.
Iterate over array without #each
This file contains 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
```ruby | |
n_arr = [1, 2, 3] | |
#=> [1, 2, 3] | |
def p_each(arr) | |
arr.size.times do |i| | |
p arr[i] * 2 | |
end | |
arr | |
end | |
# p to console 2, 4, 6 | |
p_each(n_arr) | |
#=> retval [1, 2, 3] | |
n_arr | |
#=> [1, 2, 3] | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment