Guest User

Untitled

a guest
Feb 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.23 KB | None | 0 0
  1. ## Code
  2.  
  3. class Array
  4. def dups
  5. m = []
  6. !! self.inject(Hash.new(0)) {|c,x|
  7. !! c[x] += 1
  8. !! m << x if c[x] > 1
  9. !! c
  10. !! }
  11. m
  12. end
  13. end
  14.  
  15. a = [1,2,3,4,4,5,2]
  16. puts a.dups.inspect
  17.  
  18. ## Result
  19.  
  20. [2, 4]
Add Comment
Please, Sign In to add comment