diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..0edcb41fc 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,24 +1,76 @@ -// Iteration #1: Find the maximum -function maxOfTwoNumbers() {} - +// Iteration #1: Find the maximum +function maxOfTwoNumbers(num1,num2) { + let resultado; + if (num1>num2){ + resultado=num1; + }else{ + resultado= num2; + } + return resultado; +} // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord(wordsArray) { + let palabra =""; + if (!wordsArray.length) { + return null; + }else{ + if (wordsArray.length===1){ + return wordsArray[0]; + }else{ + for (let i=0;ipalabra.length){ + palabra=wordsArray[i]; + } + } + } + } + return palabra; +} // Iteration #3: Calculate the sum -const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; - -function sumNumbers() {} +//const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; + +function sumNumbers(numbersArray) { + let resultado = 0; + if(!numbersArray.length) return 0; + if (numbersArray.length===1) return numbersArray[0]; + for (let i=0; i i){ + rep.push(existe); + } + } +} +if(rep.length>0){ + for (let i=0;i1){ + return nueva; +}else{ + return wordsArray +} +} // Iteration #6: Find elements const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; - -function doesWordExist() {} +function doesWordExist(wordsArray, word) { + let cont =0; + let existe =false; + if (!wordsArray.length) return null; + if (wordsArray[0]===word)return true; + while(cont