+ 1

What is the output of this code?

t = {a:1, b:2, c:3, d:4} res = 0 t.each {|x, y| res += y if y%2 != 0 } puts res

15th Jan 2018, 9:48 AM
h a w k
2 Answers
+ 3
The output is 4 Explanation: This code adds the odd values of dictionary t which are 1 & 3 so res =1+3=4
15th Jan 2018, 10:33 AM
Mohammed Hany
Mohammed Hany - avatar
+ 2
Thanks. It worked!
15th Jan 2018, 10:37 AM
h a w k