1. def mode(arr=[])
  2. hsh = {}
  3. max = 0
  4. arr.each do |item|
  5. # store the item in the array if, making certain to set it to one, if it's not in there
  6. hsh.has_key?(item) ? hsh[item] += 1 : hsh[item] = 1
  7. end
  8. # sort the array
  9. sorted_array = hsh.sort{|a,b| b[1]<=>a[1]}
  10. # Get the max value
  11. max = sorted_array[0][1]
  12. mode_arry = []
  13. # Count the array up until it's at it's max
  14. sorted_array.each do |arr|
  15. mode_arry << arr[0] if arr[1] >= max
  16. end
  17. mode_arry
  18. end
  19.  
  20. p mode %w(a b a a b c dd e e e) # ["e", "a"]
  21. p mode %w(a b a a b c dd e e) # ["a"]
  22. p mode %w(snowboarding is more than fun. super fun.) # ["fun."]