Skip to content

Instantly share code, notes, and snippets.

@steadweb
Forked from mattmarcello/gist:fe48cfeae486214053d6
Last active August 29, 2015 14:07
Show Gist options
  • Save steadweb/bf1ef32ba9bf4bf62d20 to your computer and use it in GitHub Desktop.
Save steadweb/bf1ef32ba9bf4bf62d20 to your computer and use it in GitHub Desktop.

What do you know about hashes?

#####(1) Instantiate a hash in two ways.

# your code here

#####(2) Store the following key-value pairs in your hash in two ways.

Key Value
'Hitchcock' ['Rear Window']
'Truffaut' ['400 Blows']
'Myers' ['Austin Powers', 'Shrek']
'fruit' 'banana'
# your code here.  

#####(3) One these key-value pairs is not like the others. Delete it.

hash = {"Hitchcock"=>["Rear Window"], "Truffaut"=>["400 Blows"], "Myers"=>["Austin Powers", "Shrek"], "banana"=>"fruit"}
# your code here

#####(4) Add an element to the array accessible via the key 'Hitchcock'

hash = {"Hitchcock"=>["Rear Window"], "Truffaut"=>["400 Blows"], "Myers"=>["Austin Powers", "Shrek"]}

# your code here.

#####(5)

Remove 'Shrek' from the array accessible via the key 'Myers'

hash = {"Hitchcock"=>["Rear Window", "Birds"], "Truffaut"=>["400 Blows"], "Myers"=>["Austin Powers", "Shrek"]}

# your code here

#####(6) Return all of the keys associated with this hash.

hash = {"Hitchcock"=>["Rear Window", "Birds"], "Truffaut"=>["400 Blows"], "Myers"=>["Austin Powers"]}

# your code here

#####(7) Return all the values associated with this hash.

hash = {"Hitchcock"=>["Rear Window", "Birds"], "Truffaut"=>["400 Blows"], "Myers"=>["Austin Powers"]}

# your code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment