To find the symmetric difference of two maps (also known as hash in Ruby), you can use the following code:
main.rb293 chars13 lines
Explanation:
map1
and map2
are the two maps whose symmetric difference we want to findmap1
and map2
, and for each common key, we decide whether to keep the old value or the new valuenil
)[old_value, new_value]
)nil
values and convert the result back to a hashgistlibby LogSnag