Ruby - Hashes
You have two hashes:
h1 = {a: 1, b: 2, c: 3}h2 = {b: 20, d: 4}You want to update h1 with h2 but only keep keys from h2 that have values greater than 10. Which code correctly does this?
You have two hashes:
h1 = {a: 1, b: 2, c: 3}h2 = {b: 20, d: 4}You want to update h1 with h2 but only keep keys from h2 that have values greater than 10. Which code correctly does this?
h2 keys with values > 10select { |k, v| v > 10 } to keep only keys with values greater than 10.h1 with filtered h2update to modify h1 in place with the filtered hash.merge! also updates but update is clearer; merge returns new hash and does not modify h1.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions