kareemgrant
2/15/2014 - 5:24 PM

State Capital Assignment - Ruby Hashes and Arrays

State Capital Assignment - Ruby Hashes and Arrays

[{:us_state=>"Alabama", :state_capital=>"Montgomery", :population=>"4822023"},
 {:us_state=>"Alaska", :state_capital=>"Juneau", :population=>"731449"},
 {:us_state=>"Arizona", :state_capital=>"Phoenix", :population=>"6553255"},
 {:us_state=>"Arkansas",
  :state_capital=>"Little Rock",
  :population=>"2949131"},
 {:us_state=>"California",
  :state_capital=>"Sacramento",
  :population=>"38041430"},
 {:us_state=>"Colorado", :state_capital=>"Denver", :population=>"5187582"},
 {:us_state=>"Connecticut",
  :state_capital=>"Hartford",
  :population=>"3590347"},
 {:us_state=>"Delaware", :state_capital=>"Dover", :population=>"917092"},
 {:us_state=>"Florida",
  :state_capital=>"Tallahassee",
  :population=>"19317568"},
 {:us_state=>"Georgia", :state_capital=>"Atlanta", :population=>"9919945"},
 {:us_state=>"Hawaii", :state_capital=>"Honolulu", :population=>"1392313"},
 {:us_state=>"Idaho", :state_capital=>"Boise", :population=>"1595728"},
 {:us_state=>"Illinois",
  :state_capital=>"Springfield",
  :population=>"12875255"},
 {:us_state=>"Indiana",
  :state_capital=>"Indianapolis",
  :population=>"6537334"},
 {:us_state=>"Iowa", :state_capital=>"Des Moines", :population=>"3074186"},
 {:us_state=>"Kansas", :state_capital=>"Topeka", :population=>"2885905"},
 {:us_state=>"Kentucky", :state_capital=>"Frankfort", :population=>"4380415"},
 {:us_state=>"Louisiana",
  :state_capital=>"Baton Rouge",
  :population=>"4601893"},
 {:us_state=>"Maine", :state_capital=>"Augusta", :population=>"1329192"},
 {:us_state=>"Maryland", :state_capital=>"Annapolis", :population=>"5884563"},
 {:us_state=>"Massachusetts",
  :state_capital=>"Boston",
  :population=>"6646144"},
 {:us_state=>"Michigan", :state_capital=>"Lansing", :population=>"9883360"},
 {:us_state=>"Minnesota", :state_capital=>"St. Paul", :population=>"5379139"},
 {:us_state=>"Mississippi", :state_capital=>"Jackson", :population=>"2984926"},
 {:us_state=>"Missouri",
  :state_capital=>"Jefferson City",
  :population=>"6021988"},
 {:us_state=>"Montana", :state_capital=>"Helena", :population=>"1005141"},
 {:us_state=>"Nebraska", :state_capital=>"Lincoln", :population=>"1855525"},
 {:us_state=>"Nevada", :state_capital=>"Carson City", :population=>"2758931"},
 {:us_state=>"New Hampshire",
  :state_capital=>"Concord",
  :population=>"1320718"},
 {:us_state=>"New Jersey", :state_capital=>"Trenton", :population=>"8864590"},
 {:us_state=>"New Mexico", :state_capital=>"Santa Fe", :population=>"2085538"},
 {:us_state=>"New York", :state_capital=>"Albany", :population=>"19570261"},
 {:us_state=>"North Carolina",
  :state_capital=>"Raleigh",
  :population=>"9752073"},
 {:us_state=>"North Dakota",
  :state_capital=>"Bismarck",
  :population=>"699628"},
 {:us_state=>"Ohio", :state_capital=>"Columbus", :population=>"11544225"},
 {:us_state=>"Oklahoma",
  :state_capital=>"Oklahoma City",
  :population=>"3814820"},
 {:us_state=>"Oregon", :state_capital=>"Salem", :population=>"3899353"},
 {:us_state=>"Pennsylvania",
  :state_capital=>"Harrisburg",
  :population=>"12763536"},
 {:us_state=>"Rhode Island",
  :state_capital=>"Providence",
  :population=>"1050292"},
 {:us_state=>"South Carolina",
  :state_capital=>"Columbia",
  :population=>"4723723"},
 {:us_state=>"South Dakota", :state_capital=>"Pierre", :population=>"833354"},
 {:us_state=>"Tennessee", :state_capital=>"Nashville", :population=>"6456243"},
 {:us_state=>"Texas", :state_capital=>"Austin", :population=>"26059203"},
 {:us_state=>"Utah", :state_capital=>"Salt Lake City", :population=>"2855287"},
 {:us_state=>"Vermont", :state_capital=>"Montpelier", :population=>"626011"},
 {:us_state=>"Virginia", :state_capital=>"Richmond", :population=>"8185867"},
 {:us_state=>"Washington", :state_capital=>"Olympia", :population=>"6897012"},
 {:us_state=>"West Virginia",
  :state_capital=>"Charleston",
  :population=>"1855413"},
 {:us_state=>"Wisconsin", :state_capital=>"Madison", :population=>"5726398"},
 {:us_state=>"Wyoming", :state_capital=>"Cheyenne", :population=>"576412"}]

State Capital Assignment

This exercise will help you better understand Arrays and Hashes

Use the data provided in state_capitals.rb to write a program that does the following.

  1. Prints out the names of all states that have a population greater than 5 million.

  2. Returns the name of the capital when given the name of the state.

  3. Returns the name of the state when given the name of the capital.

  4. Returns the state with the 27th highest population.

  5. Returns a list of all the state names that start with a letter O.