You work for a tourism agency, and your job is to promote amusement parks. When you're given a list of amusement parks and you need to write code to help organize the data.
Your mission, should you choose to accept it, is to group amusement parks by
- ID
- Country
Please define a test and a class to solve this problem.
You need to provide a way to get extremely fast access to amusement parks by their ID.
So given the following array:
[
{
:id=>546,
:name=>"Kalahari Resorts",
:city=>"Wisconsin Dells",
:state=>"Wisconsin",
:country=>"United States"
},
{
:id=>547,
:name=>"Little Amerricka",
:city=>"Marshall",
:state=>"Wisconsin",
:country=>"United States"
}
]
Your code should produce the following hash:
{
546 => {
:id=>546,
:name=>"Kalahari Resorts",
:city=>"Wisconsin Dells",
:state=>"Wisconsin",
:country=>"United States"
},
547 => {
:id=>547,
:name=>"Little Amerricka",
:city=>"Marshall",
:state=>"Wisconsin",
:country=>"United States"
}
}
So given the following array:
[
{
:id=>546,
:name=>"Kalahari Resorts",
:city=>"Wisconsin Dells",
:state=>"Wisconsin",
:country=>"United States"
},
{
:id=>547,
:name=>"Little Amerricka",
:city=>"Marshall",
:state=>"Wisconsin",
:country=>"United States"
},
{
:id=>2,
:name=>"Calaway Park",
:city=>"Calgary",
:state=>"Alberta",
:country=>"Canada"
}
]
Your code should produce the following hash:
{
"Canada" => [
{
:id=>2,
:name=>"Calaway Park",
:city=>"Calgary",
:state=>"Alberta",
:country=>"Canada"
}
],
"United States" => [
{
:id=>546,
:name=>"Kalahari Resorts",
:city=>"Wisconsin Dells",
:state=>"Wisconsin",
:country=>"United States"
},
{
:id=>547,
:name=>"Little Amerricka",
:city=>"Marshall",
:state=>"Wisconsin",
:country=>"United States"
}
]
}