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/.DS_Store b/starter-code/.DS_Store new file mode 100644 index 000000000..2de69c45b Binary files /dev/null and b/starter-code/.DS_Store differ diff --git a/starter-code/jasmine/.DS_Store b/starter-code/jasmine/.DS_Store new file mode 100644 index 000000000..f85fcfb0f Binary files /dev/null and b/starter-code/jasmine/.DS_Store differ diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..f29508891 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(number1, number2){ + if(number1>=number2){return number1;} + else {return number2;} +} // Finding Longest Word var words = [ @@ -11,14 +14,43 @@ var words = [ 'crackpot' ]; -// Calculating a Sum +function findLongestWord(words){ + var lengths=[], max=0; + for(var i=0; i