Created
May 6, 2015 01:44
-
-
Save erickuhn19/73c87ef00e22c9cdd42a to your computer and use it in GitHub Desktop.
DHH score challenge
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
class Event | |
attr_accessor :name | |
attr_accessor :score | |
def initialize(name, score=0) | |
@name = name | |
@score = score | |
end | |
end |
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
require_relative 'event' | |
require_relative 'game' | |
event1 = Event.new("IssueEvent", 7) | |
event2 = Event.new("IssueCommentEvent", 6) | |
event3 = Event.new("PushEvent", 5) | |
event4 = Event.new("PullRequestReviewCommentEvent", 4) | |
event5 = Event.new("WatchEvent", 3) | |
event6 = Event.new("CreateEvent", 2) | |
event7 = Event.new("AnyOtherEvent", 1) | |
new_game = Game.new("NewGame") | |
new_game.add_events_to_hash(event1) | |
new_game.add_events_to_hash(event2) | |
new_game.add_events_to_hash(event3) | |
new_game.add_events_to_hash(event4) | |
new_game.add_events_to_hash(event5) | |
new_game.add_events_to_hash(event6) | |
new_game.add_events_to_hash(event7) | |
puts new_game.total_points |
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
require_relative 'event' | |
class Game | |
attr_accessor :title | |
attr_accessor :all_events | |
def initialize(title) | |
@title = title | |
@all_events = Hash.new(0) | |
end | |
def add_events_to_hash(event) | |
@all_events[event.name] += event.score | |
end | |
def total_points | |
@all_events.values.reduce(0, :+) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment