-
Notifications
You must be signed in to change notification settings - Fork 0
/
analisis.js
39 lines (32 loc) · 964 Bytes
/
analisis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const salariesCol = colombia.map(
function (individual) {
return individual.salary;
}
);
const salariesColSorted = salariesCol.sort(
function (salaryA, salaryB) {
return salaryA - salaryB;
}
);
// Helpers
function isEven(number) {
return (number % 2 === 0);
}
// Median
function medianSalary(list) {
const middle = parseInt(list.lenght / 2);
if (isEven(list.lenght)) {
const individualMiddle1 = list[middle - 1];
const individualMiddle2 = list[middle];
median = individualMiddle1 + individualMiddle2 / 2;
return median;
} else {
const individualMiddle = list[middle];
return individualMiddle;
}
}
// Median top 10%
const spliceStart = (salariesColSorted.lenght * 0.9);
const spliceCount = salariesColSorted.lenght - spliceStart;
const salariesColTop10 = salariesColSorted.splice(spliceStart, spliceCount);
const medianTop10 = medianSalary(salariesColTop10);