Map with Index

Notes: Working with ruby 1.8.7 but 1.9 solution presented at bottom. While working on my main contract today I needed to create a new array based off mutated values of an existing array. Simple enough I’ll just use Enumerable::map right? Almost immediatley I realized I needed to make a reference to an array via the loops index. I first checked to see if a map_with_index existed similar to Enumerable::each_with_index. It doesn’t.

Continue reading

Author's picture

Brian Pearce

Software Developer, Endurance Cyclist,
Rubiest, Rustacean, and Gopher

Software Engineer

Barcelona, Spain