Ruby hash- How to count the sum of all values in the hash? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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
2 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