From 06735af1dfa77b7200f661daaf43bb51e4a3f27d Mon Sep 17 00:00:00 2001 From: BlisS Date: Sat, 6 Jan 2018 09:37:33 -0600 Subject: [PATCH 1/4] The description of the test says: "returns the length of the longest one" but the test is expecting for the string itself, i change the Readme file wich is the quck fix, but may be could be good to change the spec file to not confuse the student. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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** From 7450c21f9bf5ffac225679fb6dc04a9e56860ceb Mon Sep 17 00:00:00 2001 From: BlisS Date: Sat, 6 Jan 2018 12:23:51 -0600 Subject: [PATCH 2/4] the test are waiting for undefined but the description says false --- starter-code/tests/FunctionsAndArraysSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 () { From 102524f1784598d6754c8e9ed1580f7b820c76b5 Mon Sep 17 00:00:00 2001 From: Svenja Weiler Date: Tue, 9 Oct 2018 15:48:55 +0200 Subject: [PATCH 3/4] Done --- starter-code/src/functions-and-arrays.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..3c6d9297f 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,5 +1,13 @@ // Find the maximum - +function maxOfTwoNumbers(a,b){ + if (a > b){ + console.log(a); + } + else { + console.log(b); + } + } + maxOfTwoNumbers(998,89); // Finding Longest Word var words = [ 'mystery', @@ -11,10 +19,23 @@ var words = [ 'crackpot' ]; +function findLongestWord(words){ + var sortedword = words.sort(function (a,b){ + return b.length - a.length; + }) + return sortedword[0] + } + console.log(findLongestWord(words)) + + // Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +var reducer = (accumulator, currentValue) => accumulator + currentValue; + +console.log(numbers.reduce(reducer)); + // Calculate the Average var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; From b74f36b85214ca3c05d338481b423494a608968d Mon Sep 17 00:00:00 2001 From: Svenja Weiler Date: Tue, 8 Jan 2019 14:55:03 +0100 Subject: [PATCH 4/4] Done --- starter-code/src/functions-and-arrays.js | 96 +++++++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 3c6d9297f..2a3ba4d11 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,12 +1,15 @@ + // Find the maximum function maxOfTwoNumbers(a,b){ if (a > b){ - console.log(a); + return a; } else { - console.log(b); + return b; } } + + maxOfTwoNumbers(998,89); // Finding Longest Word var words = [ @@ -29,18 +32,54 @@ function findLongestWord(words){ // Calculating a Sum - +/* var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; var reducer = (accumulator, currentValue) => accumulator + currentValue; console.log(numbers.reduce(reducer)); +*/ + +function sumArray (array){ + curRes=0; + for(var i= 0;i