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 33db18b028c24099b311d9f4bed7c4a46e2f72b8 Mon Sep 17 00:00:00 2001 From: Christopher Vazquez Date: Mon, 29 Oct 2018 21:44:35 -0400 Subject: [PATCH 3/4] Add lab solutions --- starter-code/src/functions-and-arrays.js | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..96dc5a187 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,6 +1,17 @@ // Find the maximum +function maxOfTwoNumbers(num1, num2){ + if(num1 > num2){ + console.log(num1 + " is greater"); + }else{ + console.log(num2 + " is greater"); + } +} + +maxOfTwoNumbers(245, 124134134) + // Finding Longest Word +let longestWord = ''; var words = [ 'mystery', 'brother', @@ -11,14 +22,45 @@ var words = [ 'crackpot' ]; +function findTheLongestWord(words){ + + for(let i = 0; i < words.length; i++ ){ + if(words[i].length > longestWord.length) + longestWord = words[i]; + } + console.log("The longest word is " + longestWord); +} + +findTheLongestWord(arrayOfWords); + // Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +let counter = 0; + +function sumArray(nums){ + for(let i = 0; i < nums.length; i++) + counter += nums[i]; + console.log(counter); +} + +sumArray(numbers); // Calculate the Average var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; +let avgCounter = 0; +function averageNumbers(nums){ + for(let i = 0; i < nums.length; i++){ + avgCounter += nums[i]; + } + avgCounter /= nums.length; + console.log(avgCounter); +} + + +averageNumbers(arrayOfNumbers); // Array of Strings var wordsArr = [ 'seat', @@ -33,6 +75,20 @@ var wordsArr = [ 'palace' ]; +let avgWordCounter = 0; + +function averageWordLength(words){ + for(let i = 0; i < words.length; i++){ + avgWordCounter += words[i].length; + + } + avgWordCounter /= words.length; + console.log(avgWordCounter); +} + + +averageWordLength(lengthWords); + // Unique Arrays var wordsUnique = [ 'crab', From afa83d6c75bfa8cd4442af95d216f0b8d102899c Mon Sep 17 00:00:00 2001 From: Christopher Vazquez Date: Wed, 31 Oct 2018 18:29:46 -0400 Subject: [PATCH 4/4] Finish lab solutions --- starter-code/src/functions-and-arrays.js | 49 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 96dc5a187..78707d501 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -90,7 +90,7 @@ function averageWordLength(words){ averageWordLength(lengthWords); // Unique Arrays -var wordsUnique = [ +let uniqueWords = [ 'crab', 'poison', 'contagious', @@ -104,6 +104,21 @@ var wordsUnique = [ 'bring' ]; +let emptyArray = []; + +function uniquifyArray(words){ + for(i = 0; i < words.length; i++){ + if(emptyArray.indexOf(uniqueWords[i])=== -1){ + emptyArray.push(uniqueWords[i]); + } + + +} +console.log(emptyArray); +} + +uniquifyArray(uniqueWords); + // Finding Elements var wordsFind = [ 'machine', @@ -116,6 +131,22 @@ var wordsFind = [ 'disobedience' ]; +function doesWordExist(array,word){ + var find=false; + if (array.length < 1){ + find = false; + return find; + } + else { + array.forEach(function(a){ + if (a === word){ + find = true; + return find; + } + }) + } + return find; + } // Counting Repetion var wordsCount = [ 'machine', @@ -130,6 +161,22 @@ var wordsCount = [ 'disobedience', 'matter' ]; + +function howManyTimes(array,word){ + var counter = 0; + if (array.length < 1){ + var find = false; + return find; + } + else { + array.forEach(function(a){ + if (a === word){ + counter +=1 + } + }) + } + return counter; + } // Bonus Quest var matrix = [