Created
June 20, 2017 12:22
-
-
Save lukeredpath/2ab6f3bd0fea9450bdad7a36369f020d to your computer and use it in GitHub Desktop.
Ruby interpolate array value
This file contains hidden or 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
class Array | |
def interpolate(value) | |
map { |el| [el, value] }.flatten | |
end | |
end | |
[1, 3, 5, 6].interpolate(9) #=> [1, 9, 3, 9, 5, 9, 6, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment