Created
          February 7, 2018 17:06 
        
      - 
      
- 
        Save ailtonbsj/96e6fad841366766e520dd18249d3ea9 to your computer and use it in GitHub Desktop. 
    Standard Deviation in JS
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function stdDeviation(input, isAmostra){ | |
| let amostral = 0; | |
| if(isAmostra != null) amostral = 1; | |
| let sum = input.reduce((acc,val) => acc+val); | |
| let mean = sum/input.length; | |
| let diff2 = input.map(val => Math.pow(val - mean,2)); | |
| let sumDiff = diff2.reduce((acc,val) => acc+val); | |
| let desv = Math.sqrt(sumDiff/(input.length-amostral)); | |
| console.log(mean); | |
| console.log(desv); | |
| } | |
| stdDeviation([14,15,9,1],true); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment