I am having trouble with the syntax for reduce. I have a hash of the following format:
H = {\"Key1\" => 1, \"Key2\" => 2}
I would like t
In case of a complex hash it might be easier to map it first to an array of values, then reduce:
values = H.map do |k, v| # some complex logic here end values.reduce(:+)
Or values.reduce(0, :+) if the array might be empty.
values.reduce(0, :+)