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]
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy