-
Notifications
You must be signed in to change notification settings - Fork 0
/
promedio.js
43 lines (40 loc) · 1.3 KB
/
promedio.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
40
41
42
43
function calcularMediaAritmetica(lista){
// let sumaLista = 0;
// for(let i=0; i < lista.length; i++){
// sumaLista = sumaLista + lista[i];
// }
const sumaLista = lista.reduce(
function (valorAcumulado = 0, nuevoElemento){
return parseInt(valorAcumulado) + parseInt(nuevoElemento);
}
);
const promedioLista = sumaLista / lista.length;
return promedioLista;
}
function calculaPromedio(){
const promediototal = calcularMediaAritmetica(array);
if (array == "") alert("no has escrito nada");
else{
const getParrafo = document.getElementById("parrafoSalidaPromedio");
getParrafo.innerText= promediototal;
}
}
const array = [];
function agregaArrayPromedio(){
const input = document.getElementById("agregaPromedio");
const input1 = document.getElementById("arrayPromedio");
const value = input.value;
array.push(value);
input1.innerText = "[" + array +"]";
}
function agregaArrayAutomaticoPromedio(){
const input = document.getElementById("listaPromedio");
const input1 = document.getElementById("arrayPromedio");
const value = input.value;
for(let i=0; i<value.length; i++){
if(value[i] != " "){
array.push(value[i]);
}
}
input1.innerText = "[" + array +"]";
}