From b59c2cdd873747a4ebdcfe19f434f33776002fa3 Mon Sep 17 00:00:00 2001 From: AbiMeGab Date: Tue, 6 Sep 2022 11:40:55 -0500 Subject: [PATCH] =?UTF-8?q?Ahora=20s=C3=AD=20us=C3=A9=20una=20funci=C3=B3n?= =?UTF-8?q?,=20ya=20entend=C3=AD=20m=C3=A1s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- js/main.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 js/main.js diff --git a/index.html b/index.html index 12a902b..bbdd548 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@

Ejercicios

- + diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..8aa91cf --- /dev/null +++ b/js/main.js @@ -0,0 +1,20 @@ +// ## Ejercicio #2 +// María llega a su entrevista de trabajo para el rol de Desarrollador Junior y se le pide que resuelva este problema: +// Dada una lista de números [-1, 3, 4, 2, 6], escribe una función en javascript para calcular el número más pequeño. + + + +function MyMin(nums) { + var n = nums.length; + minimo = nums[n-1]; + while (n--){ + if(nums[n] < minimo) { + minimo = nums[n] + } + } + return minimo; +}; + +var nums = [-1, 3, 4, 2, 6]; +var m = MyMin(nums); +console.log(m) \ No newline at end of file