How to modify the implementation of the map function in the Array class in Ruby

Is there a way to modify the implementation of map() in the Array class such that it only affects certain indices of the array?


a = [1, 2, 3, 4, 5] { |x| x*2 }

Now, a = [1, 2, 6, 8, 10] since the map function was only used on indices 2 and 3.

Read more here:

Content Attribution

This content was originally published by FromTheEast at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: