Ruby - Blocks, Procs, and Lambdas
How can you use block parameters to swap keys and values in a hash?
h = {a: 1, b: 2}
new_hash = {}
h.each do |key, value|
new_hash[value] = key
end
puts new_hashWhat is the output?
How can you use block parameters to swap keys and values in a hash?
h = {a: 1, b: 2}
new_hash = {}
h.each do |key, value|
new_hash[value] = key
end
puts new_hashWhat is the output?
15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions