Exercise 2: Nested Hash
Practice retrieving hash data stored inside another hash.
We'll cover the following...
Problem statement
We have a nested hash called dictionary
that contains other hashes as stored values. We also have a symbol called key
. Your task is to return the keys stored in the hash that’s stored against the key
.
Example
dictionary = { :de => { :one => 'eins', :two => 'zwei', :three => 'drei' }, :en => { :one => 'one', :two => 'two', :three => 'three' }, :es => { :one => 'uno', :two => 'dos', :three => 'tres' }}
Input key = :en
Expected Output: [:one, :two, :three]
Try it yourself
Press + to interact
def return_hash(dictionary, key)result = []# Start your code herereturn resultend
to save progress
Exercise 1: Create a Hash
Exercise 3: Flip the Keys and Values
to save progress