Created
August 16, 2014 15:25
-
-
Save alacritythief/b82c2909cefa422b2ebd 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
scores = [75, 100, 85, 65, 84, 87, 95] | |
def average(array) | |
sum = 0 | |
array.each do |score| | |
sum = sum + score | |
end | |
return sum / array.count | |
end | |
def max(array) | |
i = 0 | |
p = array[0] | |
c = array.count | |
while i < c | |
if array[i] > p | |
p = array[i] | |
else | |
i += 1 | |
end | |
end | |
return p | |
end | |
def min(array) | |
i = 0 | |
p = array[0] | |
c = array.count | |
while i < c | |
if array[i] < p | |
p = array[i] | |
else | |
i += 1 | |
end | |
end | |
return p | |
end | |
puts "Average Score: #{average(scores)}%" | |
puts "Lowest Score: #{min(scores)}%" | |
puts "Max Score: #{max(scores)}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment