reducing with an index in ruby
arr = [1,2,3,4,5]
arr.each_with_index.reduce([]) do |memo, (element, index)|
# do cool code here
end
Additional bonus of the argument unpacking syntax I didn't know about.
Tweetarr = [1,2,3,4,5]
arr.each_with_index.reduce([]) do |memo, (element, index)|
# do cool code here
end
Additional bonus of the argument unpacking syntax I didn't know about.
Tweet