Tell us what’s happening:
The instruction is:
Divide your .reduce() call by the length of the array (in your variance declaration). Then, return variance.
Error:
You should divide the result of the .reduce() call by the length of the array.
Problem: If I run this through the app it runs with no errors and provides the correct value. I am at a loss here. I assume it is something simple that I am missing. Any assistance in this regard would be much appreciated. Thank you.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const getVariance = (array) => {
const mean = getMean(array);
const variance = array.reduce((acc, el) => {
const difference = el - mean;
const squared = difference ** 2;
return acc + squared / array.length;
}, 0);
return variance
}
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Learn Advanced Array Methods by Building a Statistics Calculator - Step 51