Skip to content

Instantly share code, notes, and snippets.

@townie
Created February 24, 2014 23:16
Show Gist options
  • Save townie/9199312 to your computer and use it in GitHub Desktop.
Save townie/9199312 to your computer and use it in GitHub Desktop.
One iteration of the a loop to generate min, max, average test scores
score= [75, 100, 85, 65, 84, 87, 95]
min_local = 100000000
max_local = 0
total= 0
score.inject(0) do |sum, test|
if test > max_local
max_local = test
end
if test < min_local
min_local = test
end
total = sum + test
end
puts "Min = #{min_local}"
puts "Max = #{max_local}"
puts "Average = #{total / score.length}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment