diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..ee07fa42a 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,41 +1,120 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} - +function maxOfTwoNumbers(num1, num2) { + return num1 > num2 ? num1: num2; +} // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord(words) { + let longestWord = ""; + if(!words.length) { + return null; + } + for(let i = 0; i < words.length; i++) { + if(words[i].length > longestWord.length ) { + longestWord = words[i] + } + } + return longestWord; +} + + // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} +function sumNumbers(numbers) { + let sumOfNumbers = 0; + for (let i =0; i