Skip to content

Commit

Permalink
Remove dup algo
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Sep 27, 2015
1 parent 3cc63c2 commit 827cf6a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions remove_duplicates.rb
@@ -0,0 +1,10 @@
def remove_dups xs
_xs = {}
xs.reduce([]) do |uniques, x|
uniques << x unless _xs[x]
_xs[x] = true
uniques
end
end

remove_dups(["a", "b", "b", "c", "C"]) # => ["a", "b", "c", "C"]

0 comments on commit 827cf6a

Please sign in to comment.