Skip to content

Commit

Permalink
🎨 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
UltiRequiem committed Jun 26, 2021
1 parent 83720de commit a520088
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 04-arithmetic/mediana.js
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);
11 changes: 11 additions & 0 deletions 04-arithmetic/mode.js
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));
39 changes: 39 additions & 0 deletions 05-salary/analysis.js
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,
});
17 changes: 17 additions & 0 deletions 05-salary/index.html
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>
81 changes: 81 additions & 0 deletions 05-salary/persons.js
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,
});

0 comments on commit a520088

Please sign in to comment.