diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..7a0df3058 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,4 +1,7 @@ // Find the maximum +function maxOfTwoNumbers (arg1, arg2) { + return Math.max(arg1, arg2); +} // Finding Longest Word var words = [ @@ -11,14 +14,67 @@ var words = [ 'crackpot' ]; +function findLongestWord(arr) { + let longestWord = arr[0]; + for (let i=1; i < arr.length; i++) { + if (arr[i].length > longestWord.length) { + longestWord = arr[i]; + } + } + return longestWord; +} +findLongestWord(words); + // Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +function sumArray(arr) { + let total = 0; + for (i=0; i