diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..910ea62a0 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,41 +1,127 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(num1, num2) { + if (num1>num2){ + return num1 + } + else{ + return num2 + } + +} // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord(arr) { + if(arr==false){ + return null + } + else{ + let longestWord=arr[0] + for(i=0; ilongestWord.length){ + longestWord=arr[i] + } + } + return longestWord + } +} // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} +function sumNumbers(arr) { + if(arr==false){ + return 0 + } + else{ + let result = 0 + for(i=0; i { + if(!newArray.includes(element)){ + newArray.push(element) + } + }); + return newArray + } + } + // Iteration #6: Find elements const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; -function doesWordExist() {} +function doesWordExist(wordsFind, word) { + if(wordsFind==false){ + return null + } + else{ + if(wordsFind.includes(word)){ + return true + } + else{ + return false + } + } +} @@ -78,7 +190,20 @@ const wordsCount = [ 'matter' ]; -function howManyTimes() {} +function howManyTimes(arr, word){ + if(arr=false){ + return 0 + } + else{ + let howMany = 0 + for(let i=0; i