Instantly share code, notes, and snippets.

Embed
What would you like to do?
array of floats for looping in Array
ages = [16, 15.6, 16.25, 17.1, 16.4, 15.8]
total_years = 0.0
ages.each do |age|
total_years += age
end
total_years / ages.size # => 16.191666666666666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment