Last active
October 28, 2015 13:43
-
-
Save ibanez270dx/944047f843cd6694986b to your computer and use it in GitHub Desktop.
Turn a hash into a sorted array of strings in order to compare to another hash
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 deflate(hash) | |
hash.collect do |k,v| | |
[k.to_s].push v.is_a?(Hash) ? v.to_a.flatten : v | |
end.flatten.collect(&:to_s).sort | |
end | |
event1 = { foo: 'bar', bars: [4,6,10] } | |
event2 = { bars: [10,4,6], foo: 'bar' } | |
event1 == event2 | |
# => false | |
deflate(event1) == deflate(event2) | |
# => true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment