Skip to content

Instantly share code, notes, and snippets.

@foglabs
Created August 17, 2014 16:03
Show Gist options
  • Save foglabs/727929ba38da98ec70dd to your computer and use it in GitHub Desktop.
Save foglabs/727929ba38da98ec70dd to your computer and use it in GitHub Desktop.
Min-Max-Average Systems Check
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