Created
December 28, 2011 14:22
-
-
Save akeem/1528102 to your computer and use it in GitHub Desktop.
de-duping an array of Hashes based on a given hash key
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
#assumption that all Hashes have the de-dupe key, and the de-dupe key represents a unique | |
#identifier | |
def dedupe_by_key array,key | |
collector = {} | |
array.each{|element| | |
collector[element[key]] = element | |
} | |
collector.values | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment