Skip to content

Instantly share code, notes, and snippets.

@ailtonbsj
Created February 6, 2018 16:43
Show Gist options
  • Save ailtonbsj/3b8f9bee4156d05a6ef4a0be03ae76b2 to your computer and use it in GitHub Desktop.
Save ailtonbsj/3b8f9bee4156d05a6ef4a0be03ae76b2 to your computer and use it in GitHub Desktop.
Desvio médio absoluto em JS
//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