-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83720de
commit a520088
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const NUMBERS = [100, 200, 500, 400000000]; | ||
|
||
const calcularMediaAritmetica = (arr) => | ||
arr.reduce( | ||
(valorAcumulado = 0, nuevoElemento) => valorAcumulado + nuevoElemento | ||
) / arr.length; | ||
|
||
const mitadLista1 = NUMBERS.length / 2; | ||
|
||
function isEven(n) { | ||
if (!n % 2 === 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
let mediana; | ||
|
||
if (isEven(NUMBERS.length)) { | ||
const elemento1 = NUMBERS[mitadLista1 - 1]; | ||
const elemento2 = NUMBERS[mitadLista1]; | ||
|
||
const promedioElemento1y2 = calcularMediaAritmetica([elemento1, elemento2]); | ||
|
||
mediana = promedioElemento1y2; | ||
} else { | ||
mediana = NUMBERS[mitadLista1]; | ||
} | ||
|
||
console.log(mediana); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const NUMBERS = [2, 2, 2, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 9]; | ||
|
||
function mode(arr){ | ||
return arr.sort((a,b) => | ||
arr.filter(v => v===a).length | ||
- arr.filter(v => v===b).length | ||
).pop(); | ||
} | ||
|
||
|
||
console.log(mode(NUMBERS)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const esPar = (n) => n % 2 === 0; | ||
|
||
const calcularMediaAritmetica = (lista) => | ||
lista.reduce( | ||
(valorAcumulado = 0, nuevoElemento) => valorAcumulado + nuevoElemento | ||
) / lista.length; | ||
|
||
function medianaSalarios(arr) { | ||
const mitad = arr.length / 2; | ||
|
||
if (esPar(arr.length)) { | ||
const personitaMitad1 = arr[mitad - 1]; | ||
const personitaMitad2 = arr[mitad]; | ||
|
||
const mediana = calcularMediaAritmetica([personitaMitad1, personitaMitad2]); | ||
return mediana; | ||
} | ||
return arr[mitad]; | ||
} | ||
|
||
const salarios = colombia.map((personita) => personita.salary); | ||
|
||
const salariosColSorted = salarios.sort( | ||
(salaryA, salaryB) => salaryA - salaryB | ||
); | ||
|
||
const medianaGeneral = medianaSalarios(salariosColSorted); | ||
|
||
const spliceStart = (salariosColSorted.length * 90) / 100; | ||
const spliceCount = salariosColSorted.length - spliceStart; | ||
|
||
const salaryTop10 = salariosColSorted.splice(spliceStart, spliceCount); | ||
|
||
const medianaTop10 = medianaSalarios(salaryTop10); | ||
|
||
console.log({ | ||
medianaGeneralCol: medianaGeneral, | ||
medianaTop10Col: medianaTop10, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="shortcut icon" href="./../img/favicon.png" /> | ||
<link rel="stylesheet" href="./../main.css" /> | ||
<title>Salarios</title> | ||
</head> | ||
<body> | ||
<h1>Salarios</h1> | ||
|
||
<script src="./persons.js"></script> | ||
<script src="./analysis.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const colombia = []; | ||
colombia.push({ | ||
name: 'Camila', | ||
salary: 500, | ||
}); | ||
colombia.push({ | ||
name: 'Nath', | ||
salary: 1500, | ||
}); | ||
colombia.push({ | ||
name: 'Luisa', | ||
salary: 1800, | ||
}); | ||
colombia.push({ | ||
name: 'Laura', | ||
salary: 1000, | ||
}); | ||
colombia.push({ | ||
name: 'Daniela', | ||
salary: 2200, | ||
}); | ||
colombia.push({ | ||
name: 'Esperancita', | ||
salary: 200, | ||
}); | ||
colombia.push({ | ||
name: 'Carla', | ||
salary: 500, | ||
}); | ||
colombia.push({ | ||
name: 'Antonieta', | ||
salary: 1500, | ||
}); | ||
colombia.push({ | ||
name: 'Alicia', | ||
salary: 1300, | ||
}); | ||
colombia.push({ | ||
name: 'Ana', | ||
salary: 2400, | ||
}); | ||
colombia.push({ | ||
name: 'Julia', | ||
salary: 3400, | ||
}); | ||
colombia.push({ | ||
name: 'Rosa', | ||
salary: 400, | ||
}); | ||
colombia.push({ | ||
name: 'Angélica', | ||
salary: 400, | ||
}); | ||
colombia.push({ | ||
name: 'Tatiana', | ||
salary: 400, | ||
}); | ||
colombia.push({ | ||
name: 'Lorena', | ||
salary: 600, | ||
}); | ||
colombia.push({ | ||
name: 'Carolina', | ||
salary: 1600, | ||
}); | ||
colombia.push({ | ||
name: 'Fernanda', | ||
salary: 2600, | ||
}); | ||
colombia.push({ | ||
name: 'Nora', | ||
salary: 1000, | ||
}); | ||
colombia.push({ | ||
name: 'Gisselle', | ||
salary: 2000, | ||
}); | ||
colombia.push({ | ||
name: 'Bill Gates', | ||
salary: 100000000, | ||
}); |