Skip to content

Instantly share code, notes, and snippets.

@markedmondson
Last active August 29, 2015 14:01
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 markedmondson/75ace94346e7daf88d60 to your computer and use it in GitHub Desktop.
Save markedmondson/75ace94346e7daf88d60 to your computer and use it in GitHub Desktop.
Level++
state_counts = [
OpenStruct.new(name: "BC", country: "Canada", count: 5),
OpenStruct.new(name: "Ontario", country: "CA", count: 15),
OpenStruct.new(name: "QC", country: nil, count: 25),
OpenStruct.new(name: "Oregon", country: "USA", count: 35),
OpenStruct.new(name: "WA", country: "United States", count: 45),
OpenStruct.new(name: "CA", country: nil, count: 55),
OpenStruct.new(name: "WA", country: "Australia", count: 65)
]
canada = OpenStruct.new(name: "Canada", iso: "CA", iso3: "CAN")
usa = OpenStruct.new(name: "United States", iso: "US", iso3: "USA")
australia = OpenStruct.new(name: "Australia", iso: "AU", iso3: "AUS")
# => {bc => 5, on => 15, qc => 25, or => 35, wa => 45, ca => 55, wtf=> 65}
@chrisbriend
Copy link

This currently doesn't change anything to the solution as it is not based on the country...

Let's add :

australia = OpenStruct.new(name: "Australia", iso: "AU", iso3: "AUS")

to the countries

and

OpenStruct.new(name: "WA", country: "Australia", count: 65),

to the state counts

so the output would have to be something like :

# => {ca.bc => 5, ca.on => 15, ca.qc => 25, us.or => 35, us.wa => 45, us.ca => 55, au.wa => 65}

@chrisbriend
Copy link

never mind previous comment, I was using string as key, instead of objects...

@markedmondson
Copy link
Author

Yeah it was more to ensure that "WA" wasn't being used as a state matcher for Washington.

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