neumachen
1/21/2015 - 7:08 PM

Remove value from array using index

Remove value from array using index

a = [5,5,5]
b = [5].each.with_object( a ) { |del| a.delete_at( a.index( del ) ) }
b = [5,5]

# AS A LAMBDA

subtract = lambda do |minuend, subtrahend|
  subtrahend.each.with_object( minuend ) { |del| minuend.delete_at( minuend.index( del ) ) }
end

subtract.call a, [5]
# return [5,5]