diff --git a/data/assignments.js b/data/assignments.js index e69de29..b480f44 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -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 + } \ No newline at end of file diff --git a/index.js b/index.js index a4899ce..2923976 100644 --- a/index.js +++ b/index.js @@ -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. @@ -21,7 +24,9 @@ */ +const assignmentsImport = require('./data/assignments.js') +// destructuring /** Looping and using references to arrays a given positions @@ -29,7 +34,23 @@ 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