From 59b1d96f5b3c05be5b559b46752e91a852368766 Mon Sep 17 00:00:00 2001 From: Facundo Saucedo <43495919@terciariourquiza.edu.ar> Date: Tue, 28 Apr 2026 16:14:05 -0300 Subject: [PATCH] feat: implement max, min and average functions using loops --- ejercicios.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/ejercicios.js b/ejercicios.js index c2a121f..4a80549 100644 --- a/ejercicios.js +++ b/ejercicios.js @@ -25,19 +25,19 @@ if (age >= 18) { // Tercer ejercicio: -const max = 20; +const maximum = 20; let n = 3; const multiples = []; -while (n < max) { +while (n < maximum) { multiples.push(n); n +=3; } -console.log(`Múltiples de 3 menores que ${max}:`, multiples); +console.log(`Múltiples de 3 menores que ${maximum}:`, multiples); // Cuarto ejercicio: -for (let i = 3; i < max; i += 3) { +for (let i = 3; i < maximum; i += 3) { console.log(i); } @@ -52,4 +52,39 @@ for (const fruit of fruits) { // Sexto ejercicio: const presentation = (a, b) => `Hola, mi nombre es ${a} y tengo ${b} años.`; -console.log(presentation(name, age)); \ No newline at end of file +console.log(presentation(name, age)); + +// Séptimo ejercicio: + +const numbers = [1, 3, 6, 12, 24, 5, 2, 9, 15]; + +const maxValue = (arr) => { + let max = arr[0]; + for (const num of arr) { + if (num > max) { + max = num; + } + } + return max; +}; +console.log(`El valor máximo es: ${maxValue(numbers)}`); + +const minValuer = (arr) => { + let min = arr[0]; + for (const num of arr) { + if (num < min) { + min = num; + } + } + return min; +} +console.log(`El valor mínimo es: ${minValuer(numbers)}`); + +const calculateAverage = (arr) => { + let sum = 0; + for (const num of arr) { + sum += num + } + return (sum / arr.length).toFixed(2); +} +console.log(`El promedio es: ${calculateAverage(numbers)}`); \ No newline at end of file