How do I multiply the non-negative number values of a hash by a number (for example: 2) and for the negative values just return 0?
For example, with this hash (with variable years keys):
hash = {"year2020" => "-2.0", "year2021" => "3.0", "year2022" => "1.0",...}
The result would be: (-2.0 gives 0.0, 3.0*2=6.0, 1.0*2=2.0)
result = {"year2020" => "0.0", "year2021" => "6.0", "year2022" => "2.0",...}
I tried this, but I can not figure out how to get 0 instead of the negative value:
hash.map { |k, v| [k, v.to_f * 2] }.to_h
=> {"year2020"=>-4.0, "year2021"=>6.0, "year2022"=>2.0}