I’m trying to accumulate some values if they match a condition.
Why is this snippet returning nil, when I would expect it to return 2?
[[1, 2], [2, 3], [3, 8], [4, 2]].inject(0) { |s, e| s + e[1] if e[0] <= 1}
Isn’t inject the right method for this?
You should return s;
Little cleaner