From d6a09f12fcf9c5efe4ac7992b7de2c169ba4d2f6 Mon Sep 17 00:00:00 2001 From: Robert Ledezma Date: Mon, 30 Mar 2020 20:07:30 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Hasta=20la=203ra=20iteraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes jasmine/.DS_Store | Bin 0 -> 6148 bytes src/functions-and-arrays.js | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .DS_Store create mode 100644 jasmine/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9b60dd6fe0100808a701bd6e7af0e9a7e7cd30e6 GIT binary patch literal 6148 zcmeHKO>Wab82u(m$v6l#3q)CZgT$gjO#!tMLUKd8=mH601Pef|9b3f6^+dMQ2ttrI zJwv$yC*cSjgafp1eux^UY!RaKNi*-8nfJz;=b!Nq5$jK)9#NNwIEuuEgX)TqI}*E6*YVt8a#tQ-6d-;mTSIq~x>71;-jNR>k`X`l9JK+k~> zU|ggh`h{uV!MbePI{7rFn1)bJ@RHy)p&ZH)l~AY4YPL~RH*s@v8rE2+HP#yDioq<>1J;2n9FX4!7e%6Hu+peL9jMe10N6se3gq&q zQEFU+p212ZMi5L(fm+JU5rb(t`d!2G3|1PooR~R$Fmq*QPAE)W9rL@2PR!G2YwLh@ zVA+ADZg%DVzyIg+|FX!otOM48|H=W@8u)`gmSpzUmBq=u)j^x(TY9LsdBXg2bUzNm|rO6_ORop*JKWH~?yG61A>eZxuU4Z3yyT zz#s7md=9+X-Bh4Jk8M=VNV9J|JG1t_UF~{^NcBej4pEDUG?cN{K=Tjbe%3judCwA1 z*)dYeX+Y1YOIvf%;#fomc(DJ*;8-Ff*T$%p{27EwT@N`pXKe8#9w} zap5z6Bo|p)lerKUmSashg|KkI|_aM`c`&ie5Z?&rh%8@-*@G8)LF-J5JuF zgYi*o{iVsvIL!w`o1FFs2>I|X&HHBDGo!p;*l{A)p>;zyj#?X&$=+tL^L)A)Ogi0N z*t^@^>9nCAJ?XqSJU+j?ntYjl{br{`3R~IAn#UP@hj9Z{pQB-(nfwG%vk_*Qg2I3> zAPg)R1OAxO4;Spaq}AfU#h~=yJG1LnD0UN;3 TW91MYi2Mjx8l({hZk2)G^zdL} literal 0 HcmV?d00001 diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 720d3dcf5..b46f069cb 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,16 +1,58 @@ // Iteration #1: Find the maximum +function maxOfTwoNumbers(num1, num2){ + return Math.max(num1, num2); +} + // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; +function findLongestWord(wordsArray){ + if (wordsArray.length === 0){ + return null; + } + let tam = 0; + let palabraGanadora: null; + for(let i = 0; i < wordsArray.length; i++){ + // contar el tamaño de la string + if(wordsArray[i].length > tam){ + tam = wordsArray[i].length; + palabraGanadora = wordsArray[i]; + } + } + return palabraGanadora; + //Iteración + //Encontrar la palabra más grande + // retornar palabra más grande + +}; + // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +function sumNumbers(arrayNumbers){ + if (arrayNumbers.length === 0;){ + return 0; + } +} + // Iteration #4: Calculate the average // Level 1: Array of numbers const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; + function averageNumbres(num){ + + // probar si es vacío y retornar null + if (num.length == 0){ + return null; + + let average = sumNumbers(num) / num.length + } + } + + + // Level 2: Array of strings const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; From e25a34ba7a66b661f963ae6f975e11b81f2a14da Mon Sep 17 00:00:00 2001 From: Robert Ledezma Date: Thu, 2 Apr 2020 03:54:13 +0200 Subject: [PATCH 2/2] hecho hasta el 7 --- .DS_Store | Bin 6148 -> 6148 bytes src/functions-and-arrays.js | 82 +++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index 9b60dd6fe0100808a701bd6e7af0e9a7e7cd30e6..b9ef05e2b4afa669509dfa54eb3c265d5cf3a044 100644 GIT binary patch delta 138 zcmZoMXfc=|#>B!ku~2NHo+2an#(>?7iv?Ji7`Zp|Fr8wYyn&g0vJcZWVP=M6h9ZXK zvf!e;ocz3W1_lPk$(NaRxmg)X7*c_9B@D$Nb>c{TWVI6uWj3>O@N)od+RVuEoq009 Th$9Ch0|OJ#AcoBmB5Rld#U>%I delta 68 zcmZoMXfc=|#>B)qu~2NHo+2ar#(>?7jO?3vSWYocKFOxFS&W07WivYmKL=3FW tam){ @@ -31,25 +31,63 @@ function findLongestWord(wordsArray){ const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +/* function sumNumbers(arrayNumbers){ + if (arrayNumbers.length === 0){ + return 0; + } + let suma = 0; + for (let i = 0; i < arrayNumbers.length; i++){ + suma += arrayNumbers[i] + } +return suma; +}; */ + function sumNumbers(arrayNumbers){ - if (arrayNumbers.length === 0;){ + if (arrayNumbers.length === 0){ return 0; } -} + + let resultado = sum(arrayNumbers); + + return resultado; +}; + + +function sum (arr){ + let suma = 0; + for(let i = 0; i < arr.length; i++){ + if( typeof arr[i] === "number"){ + suma += arr[i] + + } else if(typeof arr[i] === "boolean"){ + suma += arr[i] + + } else if(typeof arr[i] === "string"){ + suma += arr[i].length + + } + } + return suma; +}; + + + + // Iteration #4: Calculate the average // Level 1: Array of numbers const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; - function averageNumbres(num){ + function averageNumbers(num){ // probar si es vacío y retornar null if (num.length == 0){ return null; - let average = sumNumbers(num) / num.length + let average = sumNumbers(num) / num.length; + return average; } - } + }; @@ -71,9 +109,29 @@ const wordsUnique = [ 'bring' ]; +function uniquifyArray (arr){ + let newArr = []; + for(let i = 0; i < arr.length; i++){ + if (newArr.indexOf(arr[i].toLowerCase())===-1) newArr.push(arr[i].toLowerCase()); + } + return newArr; +}; + // Iteration #6: Find elements const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; +function doesWordExist(words, wordToSearch){ + if (words.length === 0) { + return null; + } + for (let i = 0; i< words.length; i++){ + if (words[i].includes(wordToSearch)){ + return true + } else return false + } +}; + + // Iteration #7: Count repetition const wordsCount = [ 'machine', @@ -89,6 +147,18 @@ const wordsCount = [ 'matter' ]; +function howManyTimes(arrayNumbers, wordToSearch){ + if (arrayNumbers.length === 0) { + return null; + } +let wordTimes= 0; + for (let i = 0; i< arrayNumbers.length; i++){ + if( arrayNumbers[i] === wordToSearch) + wordTimes++ + } + return wordTimes; +}; + // Iteration #8: Bonus const matrix = [