From aa058f0a6b74e7db640194172596074742e1639a Mon Sep 17 00:00:00 2001 From: Colleen Kingsley Date: Wed, 22 Jul 2020 19:06:00 -0400 Subject: [PATCH 1/6] Declare and initialize an array of assignments --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index a4899ce..b300057 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,21 @@ 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. */ +const assignments = [ + {name: 'The Perfect Lineup', completed: false}, + {name: 'Hazy Calculator', completed: true}, + {name: 'Password Validator', completed: true} +] +console.log(assignments) /** From 267876d384204a70e1c96c06c40aa92bd79d58d8 Mon Sep 17 00:00:00 2001 From: Colleen Kingsley Date: Wed, 22 Jul 2020 19:19:29 -0400 Subject: [PATCH 2/6] Import data from another file --- data/assignments.js | 12 ++++++++++++ index.js | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index e69de29..1db929c 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -0,0 +1,12 @@ +const assignments = [ + { name: 'The Perfect Lineup', completed: false }, + { name: 'Hazy Calculator', completed: true }, + { name: 'Password Validator', completed: true } +] + +function assignmentsImport(assignments) { + return assignments +} +console.log(assignmentsImport(assignments)) + +module.exports = assignmentsImport \ No newline at end of file diff --git a/index.js b/index.js index b300057..5482a6b 100644 --- a/index.js +++ b/index.js @@ -10,13 +10,7 @@ 1) Declare and initialize an array of `assignments` with `name` and `completed` properties. Name the array `assignments`. `completed` will have boolean values. */ -const assignments = [ - {name: 'The Perfect Lineup', completed: false}, - {name: 'Hazy Calculator', completed: true}, - {name: 'Password Validator', completed: true} -] -console.log(assignments) /** @@ -30,7 +24,7 @@ console.log(assignments) */ - +const assignmentsImport = require('./data/assignments.js') /** Looping and using references to arrays a given positions From a9ed330d008f6874cfab37157679cab173f6248c Mon Sep 17 00:00:00 2001 From: Colleen Kingsley Date: Wed, 22 Jul 2020 19:31:23 -0400 Subject: [PATCH 3/6] Loop through the array --- data/assignments.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/assignments.js b/data/assignments.js index 1db929c..015cf75 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -5,6 +5,9 @@ const assignments = [ ] function assignmentsImport(assignments) { + assignments.forEach(function (assignment) { + console.log({ assignment }) + }) return assignments } console.log(assignmentsImport(assignments)) From 7f899dac825003f85302a1b5aae13f0a02013da5 Mon Sep 17 00:00:00 2001 From: Colleen Kingsley Date: Wed, 22 Jul 2020 20:06:17 -0400 Subject: [PATCH 4/6] Reassign assignments to the new array --- data/assignments.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index 015cf75..0081932 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -5,11 +5,14 @@ const assignments = [ ] function assignmentsImport(assignments) { + const allAssignments = [] assignments.forEach(function (assignment) { - console.log({ assignment }) + // console.log({ assignment }) + allAssignments.push(assignment) }) - return assignments + return {allAssignments} } console.log(assignmentsImport(assignments)) + module.exports = assignmentsImport \ No newline at end of file From cd3eb7dbeb06bac63f3edaf51cc9bb0a1f51c3f6 Mon Sep 17 00:00:00 2001 From: Colleen Kingsley Date: Wed, 22 Jul 2020 20:30:52 -0400 Subject: [PATCH 5/6] Loop through array and return only completed assignments --- data/assignments.js | 6 +++++- index.js | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/data/assignments.js b/data/assignments.js index 0081932..a13e824 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -7,12 +7,16 @@ const assignments = [ function assignmentsImport(assignments) { const allAssignments = [] assignments.forEach(function (assignment) { + if (assignment.completed == true) { // console.log({ assignment }) allAssignments.push(assignment) + } }) return {allAssignments} } console.log(assignmentsImport(assignments)) -module.exports = assignmentsImport \ No newline at end of file +module.exports = { + assignmentsImport + } \ No newline at end of file diff --git a/index.js b/index.js index 5482a6b..b669f0f 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,8 @@ */ const assignmentsImport = require('./data/assignments.js') + +// destructuring /** Looping and using references to arrays a given positions From b3bc1a6f296ab2221e80e9a710687fa0ec070875 Mon Sep 17 00:00:00 2001 From: Colleen Kingsley Date: Wed, 22 Jul 2020 21:21:24 -0400 Subject: [PATCH 6/6] Change array name from allAssignments to completedAssignments --- data/assignments.js | 7 ++++--- index.js | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index a13e824..b480f44 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -5,18 +5,19 @@ const assignments = [ ] function assignmentsImport(assignments) { - const allAssignments = [] + const completedAssignments = [] assignments.forEach(function (assignment) { if (assignment.completed == true) { // console.log({ assignment }) - allAssignments.push(assignment) + completedAssignments.push(assignment) } }) - return {allAssignments} + return {completedAssignments} } console.log(assignmentsImport(assignments)) + module.exports = { assignmentsImport } \ No newline at end of file diff --git a/index.js b/index.js index b669f0f..2923976 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,23 @@ const assignmentsImport = require('./data/assignments.js') 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