Subir archivos a "/"
This commit is contained in:
46
Clase 6 Ejercicio 7.js
Normal file
46
Clase 6 Ejercicio 7.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const numeros = [1, 3, 8, 2, 18, 6];
|
||||
|
||||
function maximo(numeros) {
|
||||
|
||||
let mayor = numeros[0]; //los arrays empiezan en 0, 0 es 1, 1 es 3
|
||||
|
||||
for (let i = 1; i < numeros.length; i++) { //Empezamos dandole valor 1 a variable i, luego se empieza a recorrer todos los numeros y si son mayores a 1, despues se va sumando
|
||||
|
||||
if (numeros[i] > mayor) { //primera vuelta, comparamos y pregunta 3>1?, y continua
|
||||
mayor = numeros[i]; //busca el numero mas alto
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mayor;
|
||||
}
|
||||
|
||||
function minimo(array) {
|
||||
|
||||
let menor = array[0];
|
||||
|
||||
for (let i = 1; i < array.length; i++) {
|
||||
|
||||
if (array[i] < menor) {
|
||||
menor = array[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return menor;
|
||||
}
|
||||
|
||||
function promedio(array) {
|
||||
|
||||
let suma = 0;
|
||||
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
suma += array[i];
|
||||
}
|
||||
|
||||
return suma / array.length;
|
||||
}
|
||||
|
||||
console.log("Máximo:", maximo(numeros));
|
||||
console.log("Mínimo:", minimo(numeros));
|
||||
console.log("Promedio:", promedio(numeros));
|
||||
Reference in New Issue
Block a user