Tell us what’s happening:
Step 15
You can actually clean this logic up a bit. Using the implicit return of an arrow function, you can directly return the value of the .reduce()
method divided by the length of the array, without having to assign any variables.
Update your getMean
function as described above.
The code at the beginning is as below
const getMean = (array) => {
const sum = array.reduce((acc, el) => acc + el, 0);
const mean = sum / array.length;
return mean;
}
Below is my answer but it does not pass. I also tried log e.g. console.log(getMean([2,3])) and the code is working well to return the average from the array.
The hint is “You should use implicit return syntax to directly return the result of reduce
divided by the array length.”
Your code so far
const getMean = (array) => {
return array.reduce((acc, el) => acc + el, 0) / array.length;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Learn Advanced Array Methods by Building a Statistics Calculator - Step 15