Standard deviation javascript

后端 未结 7 1135
感情败类
感情败类 2021-01-11 10:24

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/

相关标签:
7条回答
  • 2021-01-11 11:16

    Shorthand method for getting standard deviation from an array if you don't like lots of code:

    function getStandardDeviation (array) {
      const n = array.length
      const mean = array.reduce((a, b) => a + b) / n
      return Math.sqrt(array.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n)
    }
    
    0 讨论(0)
提交回复
热议问题