Ruby: Remove duplicate values from array of arrays, keeping one copy of each unique value

require 'set'

def uniquify!(arrays)
  seen = Set.new
  arrays.each do |array|
    i = 0
    while i < array.length
      current = array[i]
      if seen.include? current
        array.delete_at(i)
      else
        seen.add(current)
        i += 1
      end
    end
  end
end
Topics: Ruby

Related Code Examples