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

Tell us what’s happening:

I’m confused on which initial value to set to 0. Should it be in the sumSquaredDifferences variable or should it be in the callback function?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const getVariance = (array) => {
  const mean = getMean(array);
  const differences = array.map(
    el => el - mean
  );
  const squaredDifferences = differences.map(
    el => el ** 2
  );
  const sumSquaredDifferences = squaredDifferences.reduce((acc, el) => acc + el);
}

// 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 48

Hi @KoduFCC

Remember to set the initial value to 0 .

I know about the initial value, but I’m not sure about the position.

Check your previous code which uses the .reduce() method.

I figured it out finally. I just didn’t think right.

1 Like

That’s the solution, but the error message Your reduce callback should return the sum of acc and el is a bit misleading, being initialValue an optional argument :slight_smile: