Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mike Hernandez #85

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lib/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Event
attr_reader :name, :ages
def initialize(name, ages)
@name = name
@ages = ages
end

def max_age
max_age = 0
ages.each do |age|
if age > max_age
max_age = age
end
end
max_age
end

def min_age
min_age = 200
ages.each do |age|
if age < min_age
min_age = age
end
end
min_age
end

def average_age
total_age = ages.sum.to_f
number_ages = ages.length.to_f
average = total_age / number_ages
average
end

def standard_deviation_age
sum_ages = ages.sum
num_ages = ages.length
average = sum_ages.to_f / num_ages.to_f
step_4_ary = []
step_4 = ages.each do |num|
step_4_ary << (num.to_f - average).round(2)
end
step_4_ary_squared = []
step_4_ary.each do |num|
step_4_ary_squared << (num ** 2).round(2)
end
step_5 = 0
step_4_ary_squared.each do |num|
step_5 += num
end
step_6 = step_5.round(1)
step_7 = step_6/ages.count.to_f
standard_deviation = Math.sqrt(step_7).round(2)
standard_deviation
end

end
3 changes: 1 addition & 2 deletions lib/games.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Games
attr_reader :events,
:year
attr_reader :events, :year

def initialize(year)
@year = year
Expand Down
32 changes: 32 additions & 0 deletions lib/standard_deviation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
ages = [24, 30, 18, 20, 41]

sum_ages = ages.sum
num_ages = ages.length
average = sum_ages.to_f / num_ages.to_f

step_4_ary = []

step_4 = ages.each do |num|
step_4_ary << (num.to_f - average).round(2)
end

step_4_ary_squared = []

step_4_ary.each do |num|
step_4_ary_squared << (num ** 2).round(2)
end

step_5 = 0

step_4_ary_squared.each do |num|
step_5 += num
end

step_6 = step_5.round(1)

step_7 = step_6/ages.count.to_f

standard_deviation = Math.sqrt(step_7).round(2)

standard_deviation

require "Pry"; binding.pry

# Your code here for calculating the standard deviation

# When you find the standard deviation, print it out
40 changes: 40 additions & 0 deletions test/event_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'minitest/autorun'
require 'minitest/pride'
require './lib/games'
require './lib/event'

class EventTest < Minitest::Test
def test_events_exist
event = Event.new("Curling", [24, 30, 18, 20, 41])

assert_instance_of Event, event
end

def test_it_has_a_name
event = Event.new("Curling", [24, 30, 18, 20, 41])

assert_equal "Curling", event.name
end

def test_ages_are_passed_as_an_arry
event = Event.new("Curling", [24, 30, 18, 20, 41])

assert_equal [24, 30, 18, 20, 41], event.ages
end

def test_there_is_a_max_and_min_age_and_average_ages
event = Event.new("Curling", [24, 30, 18, 20, 41])

assert_equal 41, event.max_age
assert_equal 18, event.min_age
assert_equal 26.6, event.average_age
end

def test_event_can_return_standard_deviation
event = Event.new("Curling", [24, 30, 18, 20, 41])

assert 8.28, event.standard_deviation_age
end


end