Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Created September 16, 2008 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redsquirrel/11025 to your computer and use it in GitHub Desktop.
Save redsquirrel/11025 to your computer and use it in GitHub Desktop.
arr = [1,1,2,2,3,3,4,5]
require 'set'
dups = Set.new
arr.each_with_index { |n, i| dups << n if n == arr[i+1] }
dups # [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment