I have this array of cities:
Bakersfield, California
Interstates: ["I-5"]
Oakland, California
Interstates: ["I-80"]
Atlanta, Georgia
Interstates: ["I-20", "I-75", "I-86"]
Cleveland, Ohio
Interstates: ["I-71", "I-77", "I-80", "I-90"]
Arlington, Texas
Interstates: ["I-20", "I-30"]
The name, the state and the interstates array are properties of each city.
I want to group them by their interstates so the final result would look something like this:
I-20: [Arlington, Atlanta]
I-5: [Bakersfield]
I-86: [Atlanta]
...
Is there a quick way to do this?
EDIT: Here is the true array, just as @wurde example.
cities = {
'Bakersfield' => {
state: 'California',
interstate: ['I-5']
},
'Oakland' => {
state: 'California',
interstate: ['I-80']
},
'Atlanta' => {
state: 'Georgia',
interstate: ["I-20", "I-75", "I-86"]
},
'Cleveland' => {
state: 'Ohio',
interstate: ["I-71", "I-77", "I-80", "I-90"]
},
'Arlington' => {
state: 'Texas',
interstate: ["I-20", "I-30"]
}
}
cities = [ {city: "Bakersfield", state: "California", Interstates: ["I-5"] }, ... ], so readers can refer tocitieswithout having to define it.