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
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ 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 a forEach loop to add in a phrase for each rebel
*/
if (rebels) {
// eslint-disable-next-line no-unused-vars
rebels.forEach(() => {
spottedRebelCalls.push('Look! Rebel scum!')
}
})

return spottedRebelCalls
}
Expand All @@ -19,7 +20,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')
}

Expand Down
33 changes: 33 additions & 0 deletions loops-object-es6.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
/* eslint-disable no-console */
/* eslint-disable no-unused-vars */
// review of loops
// 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
function calculateAge() {}

const calculateHeight = () => {}

const officeWorkers = ['Toby', 'Creed', 'Kevin', 'Michael']

officeWorkers.forEach((officeWorker) => {
console.log(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 })

// ... Object
const nameThisWay = cloneTrooper.name
const { name } = cloneTrooper

console.log({ nameThisWay, name })
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"lint": "eslint --format codeframe .",
"test": "mocha -w"
"test": "mocha -w",
"play": "node loops-object-es6.js"
},
"author": "",
"license": "ISC",
Expand Down