Skip to content

Instantly share code, notes, and snippets.

@ivorpad
Created July 8, 2015 17:31
Show Gist options
  • Save ivorpad/9c5c2f495ce7a1a0f60e to your computer and use it in GitHub Desktop.
Save ivorpad/9c5c2f495ce7a1a0f60e to your computer and use it in GitHub Desktop.
Loops: Each With Index - Bloc.io: Full Stack
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