I am trying to get the standard deviation of a user input string. I have as follows, but it returns the wrong value for SD. The calculation should go as follows: Sum values/
Quick implementation of the standard deviation function:
const sd = numbers => {
const mean = numbers.reduce((acc, n) => acc + n) / numbers.length;
return Math.sqrt(
numbers.reduce((acc, n) => (n - mean) ** 2) / numbers.length
);
};
Corrected SD version:
const correctedSd = numbers => {
const mean = numbers.reduce((acc, n) => acc + n) / numbers.length;
return Math.sqrt(
numbers.reduce((acc, n) => (n - mean) ** 2) / (numbers.length - 1)
);
};