diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..e460ec93b Binary files /dev/null and b/.DS_Store differ 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..c8df0160b Binary files /dev/null and b/starter-code/.DS_Store differ diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..bf2fc83de 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,5 +1,11 @@ // Find the maximum - +function maxOfTwoNumbers(numeroUno,numeroDos){ + if(numeroUno > numeroDos){ + return numeroUno + } else{ + return numeroDos + } +}; // Finding Longest Word var words = [ 'mystery', @@ -11,13 +17,34 @@ var words = [ 'crackpot' ]; +var word =""; + +function findLongestWord(words){ + if(words.length<=0) + return undefined; + if(words.length===1) + return words[0]; +if (words.length>0){ + word = words[0]; + for (var i= 0; i < words.length; i++){ + if (word.length < words[i].length){ + word = words[i]; + } + } + return word; +} +} + + // Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -// Calculate the Average - -var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; +function sumArray(numbers){ + if(numbers.length<=0){ + return 0; + } +} // Array of Strings var wordsArr = [ diff --git a/starter-code/tests/FunctionsAndArraysSpec.js b/starter-code/tests/FunctionsAndArraysSpec.js index 8fb25ff65..67a3b8bad 100644 --- a/starter-code/tests/FunctionsAndArraysSpec.js +++ b/starter-code/tests/FunctionsAndArraysSpec.js @@ -170,7 +170,7 @@ describe('Counting Repetion - howManyTimes', function () { }); it('returns false with an empty array', function () { - expect(howManyTimes([])).toBe(undefined); + expect(howManyTimes([])).toBe(false); }); it('returns one when the word appears only one time on the array', function () {