Suppose I have this hash
{ 1 => 4 , 2 => 3 , 4 => 1}
Now I want to make a loop where I can find any value which is greater then 3.
I know with hash.values?3
I can find the pairs has a value of 3.
But how can I find all the values which are greater of equal as 3.
Roelof
Edit 1 : I try to make this pseudo code at work in ruby.
while there are sets of 3 ones:
remove the set from the hash (h[1] -= 3)
sum 1000 to the score
end
Use #select
method:
{a: 1, b: 2, c: 3}.select{|k,v| v > 1}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With