From 38759c0ae3381e4717f906b0c998450e6d96f965 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 15:39:34 +0200 Subject: [PATCH 1/7] findLongestWord & maxOfTwoNumbers, DONE --- starter-code/src/functions-and-arrays.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 2fcd81e6e..824a1ba68 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,5 +1,15 @@ // Find the maximum +function maxOfTwoNumbers (a, b) { + if (a > b) { + return a; + } else { + return b; + } +} + + + // Finding Longest Word var words = [ 'mystery', @@ -11,6 +21,19 @@ var words = [ 'crackpot' ]; +function findLongestWord (arrayWords) { + var longestWord = ""; + if (arrayWords.length == 0) { + return undefined; + } + arrayWords.forEach(function(element) { + if (element.length > longestWord.length) { + longestWord = element; + } + }); + return longestWord; +} + // Calculating a Sum var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; From e9703adbcdc1248884d116830d0dd197eb8f7b19 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 15:56:36 +0200 Subject: [PATCH 2/7] Calculating a Sum is Work --- starter-code/src/functions-and-arrays.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 824a1ba68..cdc32fd34 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -38,6 +38,14 @@ function findLongestWord (arrayWords) { var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +function sumArray (arrayNums) { + var total = 0; + arrayNums.forEach(function(num) { + total += num; + }); + return total; +} + // Calculate the Average var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; From 198e4cb09b99355e3bd06836c0071314ac41129c Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 18:23:34 +0200 Subject: [PATCH 3/7] Calculate the Average : Array of Numbers, done --- starter-code/src/functions-and-arrays.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index cdc32fd34..b8a1eb632 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -50,6 +50,13 @@ function sumArray (arrayNums) { var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; +function averageNumbers (arrayAvg) { + if (arrayAvg.length == 0) { + return undefined; + } + return sumArray(arrayAvg) / arrayAvg.length; +} + // Array of Strings var wordsArr = [ 'seat', From 0358119e487f7bf706f3554b7561b3fd27dbd6d9 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 19:13:49 +0200 Subject: [PATCH 4/7] Calculate the Average : Array of Strings. It's work --- starter-code/src/functions-and-arrays.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index b8a1eb632..ee88dfe84 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -71,6 +71,17 @@ var wordsArr = [ 'palace' ]; +function averageWordLength (arrayAvgWords) { + var arrayLengths = []; + if (arrayAvgWords.length == 0) { + return undefined; + } + arrayAvgWords.forEach(function(letters) { + arrayLengths.push(letters.length); + }); + return averageNumbers (arrayLengths); +} + // Unique Arrays var wordsUnique = [ 'crab', From a792430f65c6a9b717bf57b633afcc3fc7905397 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 19:52:59 +0200 Subject: [PATCH 5/7] Unique Arrays is done --- starter-code/src/functions-and-arrays.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index ee88dfe84..bd73ba419 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -97,6 +97,20 @@ var wordsUnique = [ 'bring' ]; +function uniquifyArray (arrayNoUnique) { + //crea un array con los elementos de wordUnique, sólo si no existen en el nuevo array + var arrayUnique = []; + if (arrayNoUnique == 0) { + return undefined; + } + arrayNoUnique.forEach(function(word){ + if (arrayUnique.indexOf(word) < 0) { + arrayUnique.push(word) + } + }); + return arrayUnique; +} + // Finding Elements var wordsFind = [ 'machine', From ea3f4a17a105b4a8ed4de536cf88d925a259c00e Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 20:41:13 +0200 Subject: [PATCH 6/7] Finding Elements : Ok --- starter-code/src/functions-and-arrays.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index bd73ba419..53e10e3bb 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -98,7 +98,6 @@ var wordsUnique = [ ]; function uniquifyArray (arrayNoUnique) { - //crea un array con los elementos de wordUnique, sólo si no existen en el nuevo array var arrayUnique = []; if (arrayNoUnique == 0) { return undefined; @@ -123,6 +122,20 @@ var wordsFind = [ 'disobedience' ]; +function doesWordExist (arrayWordsSearch, wordSearched) { + var finded = false; + arrayWordsSearch.forEach(function(word) { + if (word === wordSearched ) { + if (finded == false){ + finded = true; + }else { + return false; + } + } + }); + return finded; +} + // Counting Repetion var wordsCount = [ 'machine', From 97a6c2775382ae4a91ae231135253582929d4105 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 21 Aug 2018 21:09:02 +0200 Subject: [PATCH 7/7] Counting Repetition: Ok --- starter-code/src/functions-and-arrays.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 53e10e3bb..7cb0f854d 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -125,7 +125,7 @@ var wordsFind = [ function doesWordExist (arrayWordsSearch, wordSearched) { var finded = false; arrayWordsSearch.forEach(function(word) { - if (word === wordSearched ) { + if (word === wordSearched) { if (finded == false){ finded = true; }else { @@ -150,6 +150,20 @@ var wordsCount = [ 'disobedience', 'matter' ]; + +function howManyTimes (arrayWordsRepeated, wordSearched) { + var count = 0; + if (arrayWordsRepeated.length == 0) { + return false; + } + arrayWordsRepeated.forEach(function(word) { + if (word === wordSearched) { + count++; + } + }); + return count; +} + // Bonus Quest var matrix = [