Created
July 8, 2015 17:31
-
-
Save ivorpad/9c5c2f495ce7a1a0f60e to your computer and use it in GitHub Desktop.
Loops: Each With Index - Bloc.io: Full Stack
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
def add_value_and_index(arr) | |
arr.each_with_index do |e, i| | |
arr[i] += i | |
end | |
end | |
a = add_value_and_index([2,1,0]) | |
p a | |
# → [2, 2, 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment