Code a function that will return the exact average grade of an array of grades. Grades can be integer or float numbers.
def average(grades) grades.sum.fdiv(grades.length) end
def average (grades)grade.sum/grade.length- def average(grades)
- grades.sum.fdiv(grades.length)
- end
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # Test.expect(boolean, [optional] message) # Test.assert_equals(actual, expected, [optional] message) # Test.assert_not_equals(actual, expected, [optional] message) Test.assert_equals(average([1, 2, 3]), 2) Test.assert_equals(average([2, 3]), 2.5) Test.assert_not_equals(average([2, 3]), 2)
- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # Test.expect(boolean, [optional] message)
- # Test.assert_equals(actual, expected, [optional] message)
- # Test.assert_not_equals(actual, expected, [optional] message)
- Test.assert_equals(average([1, 2, 3]), 2)
- Test.assert_equals(average([2, 3]), 2.5)
- Test.assert_not_equals(average([2, 3]), 2)