Created
February 15, 2012 03:17
-
-
Save deepfryed/1832891 to your computer and use it in GitHub Desktop.
unique { f(n) | n ϵ N }
This file contains 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
module Enumerable | |
def uniq_by &block | |
seen = {} | |
reject {|value| seen.key?(block.call(value)) ? true : seen[block.call(value)] = false} | |
end | |
end |
just so you know, you can do the following only for arrays
list.uniq(&:method)
yeah, dan schooled me - you can gloat dan
Where's my credit, noob :P
well i need find a good optometrist for dan /O-O/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the following does the same but uses more memory depending on dupes