Created
September 1, 2017 18:04
-
-
Save droberts-sea/93be68ce3f076c575ea90a4d4082e93f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Behavior: | |
# Can send a message | |
# Can open the first message | |
# | |
# module Messageable | |
# def setup | |
# @messages = [] | |
# end | |
# | |
# def send(msg) | |
# @messages << msg | |
# end | |
# | |
# def read_top | |
# return @messages.pop | |
# end | |
# end | |
# | |
# # Can't instantiate a module | |
# # Messageable.new # => undefined method 'new' | |
# | |
# class EmailInbox | |
# include Messageable | |
# include Comparable | |
# def initialize | |
# setup | |
# end | |
# | |
# def <=>(other) | |
# return self.messages.length <=> other.messages.length | |
# # if self.messages.length < other.messages.length | |
# # return -1 | |
# # elsif other.messages.length < self.messages.length | |
# # return 1 | |
# # else | |
# # return 0 | |
# # end | |
# end | |
# | |
# def +(other) | |
# puts "Inside our custom plus" | |
# end | |
# end | |
# | |
# inbox = EmailInbox.new | |
# inbox.send("This is a test") | |
# puts "Top message is: #{inbox.read_top}" | |
# | |
# other_inbox = EmailInbox.new | |
# | |
# inbox + other_inbox | |
# | |
# | |
# dan_hash = { | |
# "first_key": "first_value", | |
# "second_key": "second_value", | |
# "elephant": "hotdog" | |
# } | |
# | |
# dan_hash.each do |key, value| | |
# puts "#{key}: #{value}" | |
# end | |
# | |
# result = dan_hash.map do |key, value| | |
# "#{key.upcase}: #{value.reverse}" | |
# end | |
# | |
# puts "#{result}" | |
# require 'ap' | |
scores = { | |
jeremy: [10, 20, 34, 55, 86], | |
been: [11, 27, 95, 45, 33], | |
raquel: [15, 54, 23, 22, 57], | |
rosa: [5, 3, 7, 77, 34] | |
} | |
# Who has the highest average score, and what is it? | |
average_scores = scores.map do |key, value| | |
{ name: key, score: value.sum / value.length } | |
end | |
puts "#{average_scores}" | |
highest_score = average_scores.max_by do |data| | |
data[:score] | |
end | |
puts "#{highest_score}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment