Learn Advanced Array Methods by Building a Statistics Calculator - Step 53

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

Are you dividing the result by the length of the array?

Thank you, i had the /array.length in the wrong spot.

1 Like