From d31b43b144869def8fc3195f9a64adc383347bea Mon Sep 17 00:00:00 2001 From: Yor Name Date: Thu, 25 Jun 2020 19:34:32 -0400 Subject: [PATCH 1/6] Fixed bugs, completes both tests --- index.js | 7 ++++--- loops-object-es6.js | 4 ++++ package.json | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index aca98f3..0589240 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,9 @@ function spotEachRebel(rebels) { /** * @BUG ALERT - We need to be pushing 'Look! Rebel scum!' once for each rebel spotted - * The number of rebels can be expected to exactly equal the number of times that 'Look! Rebel scum!' is included + * Fixed, added for loop to return the phrase once for each rebel */ - if (rebels) { + for (let i = 0; i < rebels.length; i++) { spottedRebelCalls.push('Look! Rebel scum!') } @@ -19,7 +19,8 @@ function shootAtNothing() { let shotsAtNothing = [] /** @BUG ALERT - Looping is not quite correct */ - for (let i = 1; i < 4; i++) { + /** Fixed, set i =0 instead of 1 so that it counts 4 times not 3 */ + for (let i = 0; i < 4; i++) { shotsAtNothing.push('pew') } diff --git a/loops-object-es6.js b/loops-object-es6.js index 59a3ab5..a8ba37e 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -1,4 +1,8 @@ // review of loops +// array data type has forEach() +// for loop +// while loop + // introducing arrow functions diff --git a/package.json b/package.json index e60948d..45939f6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "lint": "eslint --format codeframe .", - "test": "mocha -w" + "test": "mocha", + "play": "node loops-object-es6.js" }, "author": "", "license": "ISC", From 1d5fe5529e4da790739259ece2f69babaa9e6278 Mon Sep 17 00:00:00 2001 From: Yor Name Date: Thu, 25 Jun 2020 19:38:19 -0400 Subject: [PATCH 2/6] Added class work loop --- loops-object-es6.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/loops-object-es6.js b/loops-object-es6.js index a8ba37e..60f531a 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -2,7 +2,10 @@ // array data type has forEach() // for loop // while loop - +for (let i = 0; i <= 10; i++) { + // eslint-disable-next-line no-console + console.log('Loop number ' + i) +} // introducing arrow functions From 1f7f818d70b5c3f92fd8305e5d992ed22ea998ba Mon Sep 17 00:00:00 2001 From: Yor Name Date: Thu, 25 Jun 2020 20:25:37 -0400 Subject: [PATCH 3/6] Did a forEach loop instead of a standard loop to fix issue --- index.js | 7 ++++--- loops-object-es6.js | 10 ++++++++++ package.json | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0589240..eaa8071 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,12 @@ function spotEachRebel(rebels) { /** * @BUG ALERT - We need to be pushing 'Look! Rebel scum!' once for each rebel spotted - * Fixed, added for loop to return the phrase once for each rebel + * Fixed, added a forEach loop to add in a phrase for each rebel */ - for (let i = 0; i < rebels.length; i++) { + // eslint-disable-next-line no-unused-vars + rebels.forEach(function (rebel) { spottedRebelCalls.push('Look! Rebel scum!') - } + }) return spottedRebelCalls } diff --git a/loops-object-es6.js b/loops-object-es6.js index 60f531a..dd8ab8a 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -1,3 +1,5 @@ +/* eslint-disable no-console */ +/* eslint-disable no-unused-vars */ // review of loops // array data type has forEach() // for loop @@ -8,7 +10,15 @@ for (let i = 0; i <= 10; i++) { } // introducing arrow functions +function calculateAge() {} +const calculateHeight = () => {} + +const officeWorkers = ['Toby', 'Creed', 'Kevin', 'Michael'] + +officeWorkers.forEach((officeWorker) => { + console.log(officeWorker) +}) // more about objects // triple dot `...` aka destructuring diff --git a/package.json b/package.json index 45939f6..c51848c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "lint": "eslint --format codeframe .", - "test": "mocha", + "test": "mocha -w", "play": "node loops-object-es6.js" }, "author": "", From 801506d1f76bc092eeab09c7e9a0d3501f0e059c Mon Sep 17 00:00:00 2001 From: Yor Name Date: Thu, 25 Jun 2020 20:40:07 -0400 Subject: [PATCH 4/6] Finished the class driven loops-object-es6.js --- loops-object-es6.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/loops-object-es6.js b/loops-object-es6.js index dd8ab8a..50c8110 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -21,4 +21,15 @@ officeWorkers.forEach((officeWorker) => { }) // more about objects +const cloneTrooper = { + name: 'Fin', + rank: 'Lead' +} + +cloneTrooper.rank = 'E1' + // triple dot `...` aka destructuring +const [firstPerson, secondPerson, ...everyOneElse] = officeWorkers + +console.log({ firstPerson, secondPerson, everyOneElse }) + From 12095b63e9af90181cb6168116e12b2516272e93 Mon Sep 17 00:00:00 2001 From: Yor Name Date: Thu, 25 Jun 2020 20:43:14 -0400 Subject: [PATCH 5/6] Finished the class driven loops-object-es6.js --- loops-object-es6.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/loops-object-es6.js b/loops-object-es6.js index 50c8110..4c76a32 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -33,3 +33,8 @@ const [firstPerson, secondPerson, ...everyOneElse] = officeWorkers console.log({ firstPerson, secondPerson, everyOneElse }) +// ... Object +const nameThisWay = cloneTrooper.name +const { name } = cloneTrooper + +console.log({ nameThisWay, name }) From 1def2dd6f2bd2624248870d5d38f642f78acbf03 Mon Sep 17 00:00:00 2001 From: Yor Name Date: Fri, 26 Jun 2020 13:20:29 -0400 Subject: [PATCH 6/6] Finishing up --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index eaa8071..0ff3640 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ function spotEachRebel(rebels) { * Fixed, added a forEach loop to add in a phrase for each rebel */ // eslint-disable-next-line no-unused-vars - rebels.forEach(function (rebel) { + rebels.forEach(() => { spottedRebelCalls.push('Look! Rebel scum!') })