forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeanAbsoluteDeviation.js
More file actions
Latest commit
21 lines (20 loc) · 630 Bytes
/
Copy pathMeanAbsoluteDeviation.js
File metadata and controls
21 lines (20 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import{mean}from'./AverageMean.js'
/**
*@function meanAbsoluteDeviation
*@description Calculates the mean absolute deviation of list of numbers
* @param {Integer} data
* @returns meanAbsoluteDeviation([2,34,5,0,-2]) = 10.480
* @url https://en.wikipedia.org/wiki/Average_absolute_deviation
*/
functionmeanAbsoluteDeviation(data){
if(!Array.isArray(data)){
thrownewTypeError('Invalid Input')
}
letabsoluteSum=0
constmeanValue=mean(data)
for(constdataPointofdata){
absoluteSum+=Math.abs(dataPoint-meanValue)
}
returnabsoluteSum/data.length
}
export{meanAbsoluteDeviation}