Last active
February 11, 2022 11:41
-
-
Save karlosmid/0680444e8581a57784974f84882fe152 to your computer and use it in GitHub Desktop.
birthdays manipulation
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
def reverse_birthdays birthdays | |
result = {} | |
birthdays.map { |day,names| names.map { |name| result[name] = day } } | |
result | |
end | |
actual = {"2019-01-01"=>["karlo01", "karlo02"], "2019-01-02"=>["ben01", "ben02"]} | |
expected = {"karlo01"=>"2019-01-01", "karlo02"=>"2019-01-01", "ben01"=>"2019-01-02", "ben02"=>"2019-01-02"} | |
expected == reverse_birthdays(actual) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hash#invert might also be interesting solution, but it doesn't work for this example: