How to select unique elements

Helper method This method uses the helper: class Array def difference(other) h = other.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 } reject { |e| h[e] > 0 && h[e] -= 1 } end end This method is similar to Array#-. The difference is illustrated in the following example: a = [3,1,2,3,4,3,2,2,4] b = [2,3,4,4,3,4] a – … Read more