From f9c62c867d3945ec6d4d929a211e4b71109d5300 Mon Sep 17 00:00:00 2001 From: Alvin Date: Wed, 22 Jul 2020 19:11:38 -0400 Subject: [PATCH 1/5] initialize assignments array --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a4899ce..50b3626 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,14 @@ 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 + 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. */ - +let assignments = [{name: '', completed: false}] /** From 9a94101dc97b18c077ef2d64bf4559b0d56324b4 Mon Sep 17 00:00:00 2001 From: Alvin Date: Wed, 22 Jul 2020 19:37:53 -0400 Subject: [PATCH 2/5] follow steps 2a and 2b --- data/assignments.js | 7 +++++++ index.js | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index e69de29..ef2b02c 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -0,0 +1,7 @@ + +const assignments = [ + {name: 'Alice',completed: false}, + {name: 'Beryl', completed: false }, + {name: 'Carol', completed: false}] + +module.exports = { assignments } diff --git a/index.js b/index.js index 50b3626..672b008 100644 --- a/index.js +++ b/index.js @@ -9,8 +9,7 @@ 1) Declare and initialize an array of `assignments` with `name` and `completed` properties. Name the array `assignments`. `completed` will have boolean values. */ -let assignments = [{name: '', completed: false}] - +const { assignments } = require('./data/assignments') /** Referencing code in other files From 031a4e6479e39350b2a0e54205ebb4cb5669b87b Mon Sep 17 00:00:00 2001 From: Alvin Date: Wed, 22 Jul 2020 20:08:48 -0400 Subject: [PATCH 3/5] review step 3 --- data/assignments.js | 2 +- index.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index ef2b02c..396017d 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -1,7 +1,7 @@ const assignments = [ {name: 'Alice',completed: false}, - {name: 'Beryl', completed: false }, + {name: 'Beryl', completed: true }, {name: 'Carol', completed: false}] module.exports = { assignments } diff --git a/index.js b/index.js index 672b008..4fc4598 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,9 @@ const { assignments } = require('./data/assignments') 3) Loop through the data using a for loop. Just console.log within the loop to show each item within the array */ - +for(let i = 0;i< assignments.length; i++) { + console.log(assignments[i]) +} /** Looping and Assignment @@ -39,6 +41,11 @@ const { assignments } = require('./data/assignments') */ +let allAssignments = [] +for(let i = 0; i Date: Wed, 22 Jul 2020 20:55:10 -0400 Subject: [PATCH 4/5] review step 3 and 4 --- index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 4fc4598..6e2056b 100644 --- a/index.js +++ b/index.js @@ -40,13 +40,12 @@ for(let i = 0;i< assignments.length; i++) { 4) Declare a new array named `allAssignments`. Loop through the `assignments` array data using a for loop and assign each item from `assignments` to the new `allAssignments` array */ - +console.log('= = = = = = = = =') let allAssignments = [] for(let i = 0; i Date: Wed, 22 Jul 2020 21:05:36 -0400 Subject: [PATCH 5/5] Update solution to four to use filter method --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index 6e2056b..4589990 100644 --- a/index.js +++ b/index.js @@ -66,4 +66,16 @@ assignments.forEach(function(item){ } }) +function isCompleted (obj) { + for(let key in obj) { + const value = obj[key] + if (key === 'completed') { + return value + } + } +} + +let completedAssignments2 = assignments.filter(isCompleted) + console.log({completedAssignments}) +console.log({completedAssignments2})