Skip to content

Instantly share code, notes, and snippets.

@alacritythief
Created August 16, 2014 15:25
Show Gist options
  • Save alacritythief/b82c2909cefa422b2ebd to your computer and use it in GitHub Desktop.
Save alacritythief/b82c2909cefa422b2ebd to your computer and use it in GitHub Desktop.
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