Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created December 4, 2012 12:59
Show Gist options
  • Save michaelfeathers/4203595 to your computer and use it in GitHub Desktop.
Save michaelfeathers/4203595 to your computer and use it in GitHub Desktop.
# :: [[a,b]] -> (a..a) -> b -> [[a,b]]]
def spread mappings, range, default_value = 0
occupied = Hash[mappings]
range.map { |index| [index, occupied[index] || default_value] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment