0

[SOLVED] I seriously need help on this

The question is: h = {a:8, b:9, c:18} sum = 0 h.each {|key, val| sum+= } puts sum WHAT IS IT PLEASE

11th Aug 2020, 7:50 PM
DigitalIsaax
DigitalIsaax - avatar
3 Antworten
+ 5
What is this code snippet doing? Its utilizing each method for adding all the values from the key-value pairs of a dictionary h. each method in ruby: https://www.thoughtco.com/using-each-beginning-ruby-control-structures-2641202 https://code.sololearn.com/c908U4Fm6d91/?ref=app
11th Aug 2020, 8:12 PM
minirkk
minirkk - avatar
+ 6
# DigitalIsaax you're welcome :) , here's a simple way to achieve the same thing. h = {a:8, b:9, c:18} puts h.values.sum
11th Aug 2020, 8:18 PM
minirkk
minirkk - avatar
+ 4
Hey thanks for helping I was really stuck
11th Aug 2020, 8:15 PM
DigitalIsaax
DigitalIsaax - avatar