Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 664 Bytes

grasshopper_array_mean.md

File metadata and controls

32 lines (23 loc) · 664 Bytes

Description

Find Mean

Find the mean (average) of a list of numbers in an array.

Information

To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list.

For an example list of 1, 3, 5, 7

  1. Add all of the numbers
1+3+5+7 = 16
  1. Divide by the number of values in the list. In this example there are 4 numbers in the list.
16/4 = 4
  1. The mean (or average) of this list is 4

My Solution

def find_average(nums)
  nums.empty? ? 0 : nums.sum.to_f / nums.count
end