Tell us what’s happening:
My code:
const getVariance = (array) => {
const mean = getMean(array);
const variance = array.reduce((acc, el) => {
const difference = el - mean;
const squared = difference ** 2;
return acc + squared;
}, 0/array.length);
return variance
}
Error message: you should divide the result of the reduce( ) call by the length of the array.
What’s wrong?
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;
}, 0/array.length);
return variance
}
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (iPad; CPU OS 18_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/133.0.6943.33 Mobile/15E148 Safari/604.1
Challenge Information:
Learn Advanced Array Methods by Building a Statistics Calculator - Step 53