ruby 使用索引从数组中删除值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 使用索引从数组中删除值相关的知识,希望对你有一定的参考价值。

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]

以上是关于ruby 使用索引从数组中删除值的主要内容,如果未能解决你的问题,请参考以下文章