Skip to content

Instantly share code, notes, and snippets.

@rosiehoyem
Created October 3, 2013 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosiehoyem/6809378 to your computer and use it in GitHub Desktop.
Save rosiehoyem/6809378 to your computer and use it in GitHub Desktop.
Hash homework day #8, pigeon organizer
########################
# NYC PIGEON ORGANIZER #
########################
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
:white => ["Queenie", "Andrew", "Ms .K", "Alex"],
:brown => ["Queenie", "Alex"]
},
:gender => {
:male => ["Alex", "Theo", "Peter Jr.", "Andrew", "Lucky"],
:female => ["Queenie", "Ms .K"]
},
:lives => {
"Subway" => ["Theo", "Queenie"],
"Central Park" => ["Alex", "Ms .K", "Lucky"],
"Library" => ["Peter Jr."],
"City Hall" => ["Andrew"]
}
}
# collect_names(pigeon_data)
names = []
pigeon_data.each do | attribute, attrib_array |
attrib_array.each do | property, name|
names << name
end
end
names.flatten.uniq!
# create_list(names, pigeon_data)
pigeon_list = {}
names.each do |name|
pigeon_list[name] = { :color => [], :gender => "", :lives => ""}
pigeon_data.each do | attribute, attrib_array |
attrib_array.each do | property, pigeons |
pigeon_list[name][attribute] << property if pigeons.include?(name)
end
end
pigeon_list
end
@esperandus
Copy link

Awww! Fun with hashes / Associative arrays! now youre cooking with gas! Hope youre having fun!

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