forked from marquez.juan/javascript-primeros-ejercicios
feat: add function for numbers max,min and average
This commit is contained in:
@@ -56,3 +56,41 @@ function presentation(name,age){
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(presentation(name,age));
|
console.log(presentation(name,age));
|
||||||
|
|
||||||
|
// Septimo ejercicio
|
||||||
|
|
||||||
|
const numbers = [ 1, 5, 10, 16, 32, 58]
|
||||||
|
|
||||||
|
function numeroMaximo(array){
|
||||||
|
let max = array[0];
|
||||||
|
for(const num of array){
|
||||||
|
if(num > max){
|
||||||
|
max = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
console.log(`El valor maximo es ${numeroMaximo(numbers)}`);
|
||||||
|
|
||||||
|
function numeroMinimo(array){
|
||||||
|
let min = array[0];
|
||||||
|
for(const num of array){
|
||||||
|
if(num < min){
|
||||||
|
min = num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
console.log(`El valor minimo es ${numeroMinimo(numbers)}`);
|
||||||
|
|
||||||
|
function numeroPromedio(array){
|
||||||
|
let sum = 0;
|
||||||
|
let cantidad = 0;
|
||||||
|
for(const num of array){
|
||||||
|
sum+=num
|
||||||
|
cantidad++
|
||||||
|
}
|
||||||
|
return (sum/cantidad)
|
||||||
|
}
|
||||||
|
console.log(`El promedio es ${numeroPromedio(numbers)}`);
|
||||||
Reference in New Issue
Block a user