Find the mean (average) of a list of numbers in an array.
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
- Add all of the numbers
1+3+5+7 = 16
- Divide by the number of values in the list. In this example there are 4 numbers in the list.
16/4 = 4
- The mean (or average) of this list is 4
def find_average(nums)
nums.empty? ? 0 : nums.sum.to_f / nums.count
end