diff --git a/README.md b/README.md index 5d11b9e6e..81bf62d26 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Define a function `maxOfTwoNumbers` that takes two numbers as arguments and retu ## Finding Longest Word -Write a function `findLongestWord` that takes an array of words and returns the length of the longest one. If there are 2 with the same length, it should return the first occurrence. +Write a function `findLongestWord` that takes an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence. **Starter Code** diff --git a/starter-code/SpecRunner.html b/starter-code/index.html similarity index 100% rename from starter-code/SpecRunner.html rename to starter-code/index.html diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..cedcee19a 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,5 +1,10 @@ // Find the maximum +function maxOfTwoNumbers (a,b) { + if (a>b) return a; + else return b; +} + // Finding Longest Word var words = [ 'mystery', @@ -11,14 +16,49 @@ var words = [ 'crackpot' ]; +function findLongestWord (arr) { + if(arr.length == 0){ + return undefined; + } + var longestWord = []; + for (let i=0; ilongestWord.length) { + longestWord=arr[i]; + } + } + return longestWord; +} + + // Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +function sumArray (arr) { + var sum = 0; + for (let i =0; i