diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..80ae385ad 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,24 +1,72 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(a, b) { + if (a>b){ + return a ; + } else { + return b ; + } +} +console.log(maxOfTwoNumbers(100, 20)) // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord(arr) { + let longestWord = arr[0] + if (arr.length === 0 ) {return null} + else { + for (let i = 0; i longestWord.length){ + longestWord = arr[i] + } + } + return longestWord + } +} + +let empty = ["apple"] +let result = findLongestWord(empty) +console.log(result) // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} - +function sumNumbers(arr) { + let addition = 0 + for (let i = 0; i { + if (item === word){ + counter += 1 + } + }) + return counter + } +} + +console.log(howManyTimes(wordsCount, 'matter')) +