Challenge 1: Average of Numbers
Given an array of numbers, compute the average of those numbers recursively.
We'll cover the following
Problem Statement
Implement a function that computes the average of all the numbers in an array.
If we have numbers and each number is denoted by , the average is the of the numbers divided by . This is represented as follows:
Try solving this problem recursively.
Input
- A
testVariable
containing an array of numbers. - The
currentIndex
of the array.
Note: The array,
testVariable
, can’t be empty, i.e., it will always have at least one element.
Output
Average of all numbers in the input array.
Sample Input
testVariable = [10, 2, 3, 4, 8, 0]
currentIndex = 0
Sample Output
4.5
Try it Yourself
Try this challenge yourself before examining the solution. Good luck!
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.