Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
}

Expand All @@ -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

29 changes: 28 additions & 1 deletion loops-object-es6.js
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"eslint": "^6.8.0",
"mocha": "^7.1.2"
}
}
}