agrega array numeros y funciones de max minimo y promedio
This commit is contained in:
@@ -35,4 +35,33 @@ for (const fruta of frutas) {
|
||||
function presentarse(nombre, edad) {
|
||||
return `Me llamo ${nombre} y tengo tengo ${edad} años.`
|
||||
}
|
||||
console.log(presentarse("maximo", 19))
|
||||
console.log(presentarse("maximo", 19));
|
||||
const numeros = [ 1, 5 , 7 , 8 , 13 ]
|
||||
function max(numeros){
|
||||
let Mayor= numeros[0];
|
||||
for (const numero of numeros) {
|
||||
if (numero > Mayor){
|
||||
mayor = numero}
|
||||
}
|
||||
return mayor
|
||||
}
|
||||
console.log(max(numeros));
|
||||
function Minimo(numeros){
|
||||
let Menor= numeros[0];
|
||||
for (const numero of numeros) {
|
||||
if (numero < Menor){
|
||||
Menor = numero}
|
||||
}
|
||||
return Menor
|
||||
}
|
||||
console.log(Minimo(numeros));
|
||||
function promedio(numeros){
|
||||
let cantidad= 0
|
||||
let suma= 0
|
||||
for(const numero of numeros) {
|
||||
cantidad++
|
||||
suma=suma+numero}
|
||||
|
||||
return total=suma/cantidad
|
||||
}
|
||||
console.log(promedio(numeros));
|
||||
|
||||
Reference in New Issue
Block a user