I’m wondering if there is a cleaner approach to this:
hash = { 1 => 10, 2 => 33, 3 => 5, 4 => 33 }
hash.reject { |key, value| value != hash.values.max }.keys
I want to be able to do this:
{ 1 => 10, 2 => 33, 3 => 5, 4 => 33 }.reject { |key, value| value != HASH_BEING_OPERATED_ON.values.max }.keys
But the block within reject needs a reference to the hash that reject is operating upon. Is it possible?
Besides whether possible or not, you shouldn’t be doing that because it is inefficient. You are recalculating the max value within each iteration. Why not just calculate max before iteration?