Skip to content

Instantly share code, notes, and snippets.

@DNNX

DNNX/ README.md Secret

Created April 16, 2017 18:22
Show Gist options
  • Save DNNX/c3452ebd6317b66f79057a41f707115e to your computer and use it in GitHub Desktop.
Save DNNX/c3452ebd6317b66f79057a41f707115e to your computer and use it in GitHub Desktop.
excellent-bonus

The correct answer is: it depends. Depends on the version of Ruby you're running currently and possibly some other factors.

# cpp.rb
def f(xs, ys)
  xs.reject! do |x|
    ys.any? { |y| y[:cnt] += x[:cnt] if x != y }
  end
end

a = [{cnt: 4}, {cnt: 2}]
f(a, a)

p a
$ rbenv local 2.2.5 && ruby cpp.rb
[{:cnt=>6}]
$ rbenv local 2.3.3 && ruby cpp.rb
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment