daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Apr 24th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. days = {
  2.   may_1: "sunny",
  3.   may_2: "cloudy",
  4.   may_3: "rainy",
  5.   may_4: "sunny",
  6.   may_5: "sunny",
  7.   may_6: "stormy",
  8.   may_7: "cloudy",
  9.   may_8: "sunny",
  10.   may_9: "rainy",
  11.   may_10: "sunny"
  12. }
  13. #This will be our input
  14. def sunny_day_counter(array)
  15.   arr = array.to_a
  16.   #Since we can't use the values method we need to find another way to access the hashes values.
  17.   #Here I turned the hash into a nested array where each sub-array holds a key value pair.;
  18.   arr.map! {|day| day[1]}
  19.   #Next I used map to pull out the values from each sub-array.
  20.   puts ar.count("sunny")
  21.   #Lastly I counted number of extracted values that were equivalent to "sunny".
  22. end
  23. sunny_day_counter(days)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top