Created
August 17, 2014 16:03
-
-
Save foglabs/727929ba38da98ec70dd to your computer and use it in GitHub Desktop.
Min-Max-Average Systems Check
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
scores = [75, 100, 85, 65, 84, 87, 95] | |
def min(numb_array) | |
sorter = numb_array[0] | |
numb_array.each do |each_num| | |
if each_num.to_f <= sorter | |
sorter = each_num.to_f | |
end | |
end | |
sorter | |
end | |
def max(numb_array) | |
sorter = numb_array[0] | |
numb_array.each do |each_num| | |
if each_num.to_f >= sorter | |
sorter = each_num.to_f | |
end | |
end | |
sorter | |
end | |
def avg(numb_array) | |
# sum = 0 | |
avg = (numb_array.inject(:+))/(numb_array.count).to_f | |
avg | |
end | |
puts "The minimum score is: " | |
puts min(scores) | |
puts "The maximum score is: " | |
puts max(scores) | |
puts "The average score is: " | |
puts avg(scores) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment