Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- days = {
- may_1: "sunny",
- may_2: "cloudy",
- may_3: "rainy",
- may_4: "sunny",
- may_5: "sunny",
- may_6: "stormy",
- may_7: "cloudy",
- may_8: "sunny",
- may_9: "rainy",
- may_10: "sunny"
- }
- #This will be our input
- def sunny_day_counter(array)
- arr = array.to_a
- #Since we can't use the values method we need to find another way to access the hashes values.
- #Here I turned the hash into a nested array where each sub-array holds a key value pair.;
- arr.map! {|day| day[1]}
- #Next I used map to pull out the values from each sub-array.
- puts ar.count("sunny")
- #Lastly I counted number of extracted values that were equivalent to "sunny".
- end
- sunny_day_counter(days)
Add Comment
Please, Sign In to add comment