- 1

Ruby hash- How to count the sum of all values in the hash?

Fill in the blanks to count the sum of all values in the hash. h = {a:2, b:8, c:73} sum = 0 h.___ do |k, v| sum+=____

11th May 2020, 5:11 PM
ŠŠ½Š“рŠµŠ¹ Š Ń‹Š±Š°ŠŗŠ¾Š²
ŠŠ½Š“рŠµŠ¹ Š Ń‹Š±Š°ŠŗŠ¾Š² - avatar
3 Answers
+ 1
No idea? h = {a:2, b:8, c:73} sum = 0 h.each do |k, v| sum+=v
11th May 2020, 7:47 PM
Lothar
Lothar - avatar
+ 1
Thank you
11th May 2020, 8:39 PM
ŠŠ½Š“рŠµŠ¹ Š Ń‹Š±Š°ŠŗŠ¾Š²
ŠŠ½Š“рŠµŠ¹ Š Ń‹Š±Š°ŠŗŠ¾Š² - avatar