From bd8a3891c4a0a09d643213acb81927608032a48e Mon Sep 17 00:00:00 2001 From: xworld2000 Date: Thu, 9 Jul 2020 09:27:18 -0400 Subject: [PATCH] Figured this out finally --- index.js | 23 ++++++++++++++++------- loops-object-es6.js | 29 ++++++++++++++++++++++++++++- package.json | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index aca98f3..c857759 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,10 @@ 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 */ - if (rebels) { - spottedRebelCalls.push('Look! Rebel scum!') + for (let index = 0; index < rebels.length; index++) { + if (rebels) { + spottedRebelCalls.push('Look! Rebel scum!') + } } return spottedRebelCalls @@ -19,7 +21,7 @@ function shootAtNothing() { let shotsAtNothing = [] /** @BUG ALERT - Looping is not quite correct */ - for (let i = 1; i < 4; i++) { + for (let i = 0; i < 4; i++) { shotsAtNothing.push('pew') } @@ -30,16 +32,23 @@ function shootAtNothing() { * Get lines from different movie roles * Use the Array `concat` method to put all of the movie script lines together in one */ -function deliverStormTroopersEscapeScene(rebels) { +module.exports = function deliverStormTroopersEscapeScene(rebels) { /** combine results form each part of the scene */ - const sceneSequence = [...spotEachRebel(rebels), ...shootAtNothing()] + let sceneSequence = [] + + if (rebels) { + sceneSequence = spotEachRebel(rebels).concat(shootAtNothing()) + } + else { + sceneSequence = shootAtNothing() + } return sceneSequence } -/** +/** We are not exporting an object. We are exporting a single function. Only the exported function can be directly used by code that requires this module. */ -module.exports = deliverStormTroopersEscapeScene + diff --git a/loops-object-es6.js b/loops-object-es6.js index 59a3ab5..7a60cfb 100644 --- a/loops-object-es6.js +++ b/loops-object-es6.js @@ -1,7 +1,34 @@ // review of loops - +// for loops +for (let i = 0; i <= 10; i++) { + // eslint-disable-next-line no-console + console.log('Loop # ' + i) +} // introducing arrow functions +function calculateAge(params) { +} +const calculateHeight = () => { } + +const officeWorkers = ['Toby', 'Creed', 'kevin', 'michael'] + +officeWorkers.forEach((officeWorker) => { + console.log(officeWorker) +}) // more about objects +let cloneTrooper = { + name: 'Fin', + rank: 'E1' +} + +cloneTrooper.rank = 'E2' // triple dot `...` aka destructuring + +// ... for Arrays + +const [first, ...everyOneElse] = officeWorkers + +console.log({ first, everyOneElse }) +// ... for objects + diff --git a/package.json b/package.json index e60948d..0ff8860 100644 --- a/package.json +++ b/package.json @@ -14,4 +14,4 @@ "eslint": "^6.8.0", "mocha": "^7.1.2" } -} +} \ No newline at end of file