The canonical Array difference example in Ruby is:
[ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ]
What\'s the best way to ge
class Array def subtract_once(b) h = b.inject({}) {|memo, v| memo[v] ||= 0; memo[v] += 1; memo } reject { |e| h.include?(e) && (h[e] -= 1) >= 0 } end end
I believe this does what I want. Many thanks to @glebm