Created
July 30, 2015 22:04
-
-
Save blake41/c6a1543f2a76b5f1baba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
require 'pry-nav' | |
require 'ap' | |
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"] | |
} | |
} | |
def nyc_pigeon_organizer(data) | |
pigeon_hash = {} | |
data.each_pair do |attribute, values| | |
# attribute like :color | |
# values = { | |
# :purple => ["Theo", "Peter Jr.", "Lucky"], | |
# :grey => ["Theo", "Peter Jr.", "Ms. K"], | |
# :white => ["Queenie", "Andrew", "Ms. K", "Alex"], | |
# :brown => ["Queenie", "Alex"] | |
# } | |
values.each_pair do |specific_values, pigeons| | |
# specific_values like :purple | |
# pigeons like ["Theo", "Peter Jr.", "Lucky"] | |
pigeons.each do |pigeon| | |
# pigeon like "theo" | |
# i | |
if pigeon_hash[pigeon].nil? | |
# binding.pry | |
pigeon_hash[pigeon] = {} | |
end | |
if pigeon_hash[pigeon][attribute] | |
pigeon_hash[pigeon][attribute] << specific_values.to_s | |
else | |
pigeon_hash[pigeon][attribute] = [] | |
pigeon_hash[pigeon][attribute] << specific_values.to_s | |
end | |
# either the pigeon exists | |
# it does not exist | |
end | |
end | |
end | |
# binding.pry | |
pigeon_hash | |
end | |
# start | |
# nyc_pigeon_organizer(pigeon_data) | |
pigeon_list = { | |
"Theo" => { | |
:color => ["purple", "grey"], | |
:gender => ["male"], | |
:lives => ["Subway"] | |
}, | |
"Peter Jr." => { | |
:color => ["purple", "grey"], | |
:gender => ["male"], | |
:lives => ["Library"] | |
}, | |
"Lucky" => { | |
:color => ["purple"], | |
:gender => ["male"], | |
:lives => ["Central Park"] | |
}, | |
"Ms. K" => { | |
:color => ["grey", "white"], | |
:gender => ["female"], | |
:lives => ["Central Park"] | |
}, | |
"Queenie" => { | |
:color => ["white", "brown"], | |
:gender => ["female"], | |
:lives => ["Subway"] | |
}, | |
"Andrew" => { | |
:color => ["white"], | |
:gender => ["male"], | |
:lives => ["City Hall"] | |
}, | |
"Alex" => { | |
:color => ["white", "brown"], | |
:gender => ["male"], | |
:lives => ["Central Park"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment