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: 23 additions & 0 deletions data/assignments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const assignments = [
{ name: 'The Perfect Lineup', completed: false },
{ name: 'Hazy Calculator', completed: true },
{ name: 'Password Validator', completed: true }
]

function assignmentsImport(assignments) {
const completedAssignments = []
assignments.forEach(function (assignment) {
if (assignment.completed == true) {
// console.log({ assignment })
completedAssignments.push(assignment)
}
})
return {completedAssignments}
}
console.log(assignmentsImport(assignments))



module.exports = {
assignmentsImport
}
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

We will push to github all along the way so we track our week and keep a log

a) code in git, start working. First Step: 'git checkout -b answer'
b)

Declaring an Array with Objects

1) Declare and initialize an array of `assignments` with `name` and `completed` properties. Name the array `assignments`. `completed` will have boolean values.
Expand All @@ -21,15 +24,33 @@

*/

const assignmentsImport = require('./data/assignments.js')

// destructuring
/**

Looping and using references to arrays a given positions

3) Loop through the data using a for loop. Just console.log within the loop to show each item within the array

*/

//for loop with a lot of flexibility
/* for (let index=0; index < assignments.length; index - 1) {
const assignment = assignments[index]
console.log({assignment})
}
// also flexible
for (let index in assignments.splice(2, 2)) {
const assignment = assignments[index]
console.log(index, assignment)
}

//map function
let allAssignments = assignments.map( (assignment) => {
return assignment
} )

console.log(allAssignments) */
/**

Looping and Assignment
Expand Down