Skip to content

Instantly share code, notes, and snippets.

@adeng21
Created February 23, 2014 01:20
Show Gist options
  • Save adeng21/9165230 to your computer and use it in GitHub Desktop.
Save adeng21/9165230 to your computer and use it in GitHub Desktop.
Week 1 Checkpoint
scores = [75, 100, 85, 65, 84, 87, 95]
def average(array)
total = 0
array.each {|i| total += i}
total/array.length
end
def highest(array)
first = array[0]
array.each do |i|
if i > first
first = i
end
end
return first
end
def lowest(array)
first = array[0]
array.each do |i|
if i < first
first = i
end
end
return first
end
puts "Average Score: #{average(scores)}"
puts "Highest Score: #{highest(scores)}"
puts "Lowest Score: #{lowest(scores)}"
@faizaanshamsi
Copy link

The only thing I'd add is to convert to floats instead of integers so that you get more precise results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment