diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..78add27af 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,38 +1,79 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(a, b) { + if(a > b) { + return a + } else { + return b } +} +maxOfTwoNumbers(3, 5); // Iteration #2: Find longest word -const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; - -function findLongestWord() {} - - +const words = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; + +function findLongestWord(arrayOfWords) { + let longestWord = arrayOfWords[0]; + for (let i=0; i longestWord.length) { + longestWord = arrayOfWords[i] + } + } + return longestWord; +} -// Iteration #3: Calculate the sum -const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +// Iteration #3: Calculate the sum +const myArray = [6, 12, 1, 18, 13, 16, 2, 1, 8, 12]; -function sumNumbers() {} +function sumNumbers(numbers) { + if(myArray == []) { + result === 0 + } + let result = 0; + for(let i = 0; i