Created
February 6, 2018 16:43
-
-
Save ailtonbsj/3b8f9bee4156d05a6ef4a0be03ae76b2 to your computer and use it in GitHub Desktop.
Desvio médio absoluto em JS
This file contains 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
//Desvio medio absoluto | |
function dam(input){ | |
let sum = input.reduce((acc,val) => acc+val); | |
let mean = sum/input.length; | |
let desvAbs = input.map(val => Math.abs(val - mean)); | |
let sumDesv = desvAbs.reduce((acc,val) => acc+val); | |
return sumDesv/input.length; | |
} | |
console.log(dam([34,29,39,34])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment