From 5d1ee253975f72585ab05ee8699eb053e7b02209 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 19:06:56 -0400 Subject: [PATCH 01/10] First answer working with arrays --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a4899ce..a714b28 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,19 @@ We will push to github all along the way so we track our week and keep a log + + 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 = [{ + assignments: { + name: '', + completed: true + } +}] /** From fbf30c33898da7f73bea81f7a9cbf33a602eff35 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 19:24:10 -0400 Subject: [PATCH 02/10] More details, slightly different interpretation of the instructions --- index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a714b28..9cf4c3f 100644 --- a/index.js +++ b/index.js @@ -10,11 +10,19 @@ */ let assignments = [{ - assignments: { + assignment1: { name: '', completed: true - } -}] + }, + assignment2: { + name: '', + completed: false + }, + assignment3: { + name: '', + completed: true + }, +}]; /** From 4c52789e8ff8ca961e828f9f17742f8b8968064b Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 19:45:48 -0400 Subject: [PATCH 03/10] See answer two: import and export --- data/assignments.js | 18 ++++++++++++++++++ index.js | 30 +++++++++++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index e69de29..4707985 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -0,0 +1,18 @@ +let assignments = [{ + assignment1: { + name: '', + completed: true + }, + assignment2: { + name: '', + completed: false + }, + assignment3: { + name: '', + completed: true + }, +}]; + +module.exports = { + assignments +} \ No newline at end of file diff --git a/index.js b/index.js index 9cf4c3f..311e5a2 100644 --- a/index.js +++ b/index.js @@ -9,6 +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 = [{ assignment1: { name: '', @@ -23,24 +24,31 @@ let assignments = [{ completed: true }, }]; +*/ - /** - Referencing code in other files - - 2a) Great work! Now move that array initialization out into its own file. - See ./data/assignments.js where you will initialize the data in place of inline in this function - 2b) "Import" that data into this file in place of the inline code you had in step 1 - +// Referencing code in other files + +/* 2a) Great work! Now move that array initialization out into its own file. +See ./data/assignments.js where you will initialize the data in place of inline in this function +copy/pasted the function into assignments.js and added `module.exports = { +assignments +}` +*/ + +// 2b) "Import" that data into this file in place of the inline code you had in step 1 +const { assignments } = require('./data/assignments'); + +console.log(assignments); + - */ /** 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 */ @@ -48,7 +56,7 @@ let assignments = [{ /** Looping and Assignment - + 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 */ @@ -57,7 +65,7 @@ let assignments = [{ /** Filtering - + 5) Declare a new array named `completedAssignments`. Loop through the `assignments` array data using a for loop. Use a condition to only add to `allAssignments` where there are property values with `completed` of `true` */ From c08c57db2a306987347db601c49ee45b35bdfb34 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 20:01:26 -0400 Subject: [PATCH 04/10] Use a for loop --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 311e5a2..a94e105 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,10 @@ console.log(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]) +}; + /** From 845ab4df8a309e5f9959162dbaf839818ed5b56e Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 20:13:08 -0400 Subject: [PATCH 05/10] Answer number four with ES5 notation --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a94e105..6f132e7 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ assignments // 2b) "Import" that data into this file in place of the inline code you had in step 1 const { assignments } = require('./data/assignments'); -console.log(assignments); +// console.log(assignments); @@ -52,10 +52,12 @@ console.log(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++) { + +/* + for (let i = 0; i < assignments.length; i++) { console.log(assignments[i]) }; - +*/ /** @@ -64,7 +66,14 @@ 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 */ +let allAssignments = [] +function loop(assignment) { + for (let i = 0; i < assignments.length; i++) { + return allAssignments.push(assignments[i]); + }; +}; +console.log(allAssignments); /** From e572b2159c66396190a6cd0fe2568f38cfc2bd81 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 20:16:07 -0400 Subject: [PATCH 06/10] Answer four with fat arrow syntax --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index 6f132e7..a1cdb26 100644 --- a/index.js +++ b/index.js @@ -68,13 +68,22 @@ const { assignments } = require('./data/assignments'); */ let allAssignments = [] +/* function loop(assignment) { for (let i = 0; i < assignments.length; i++) { return allAssignments.push(assignments[i]); }; }; console.log(allAssignments); +*/ + +let assigning = loop => { + for (let i = 0; i < assignments.length; i++) { + return allAssignments.push(assignments[i]); + }; +} +console.log(assigning(), allAssignments); /** Filtering From 8741efbcc11c8a61251aa1503823bcdd58bf78dc Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 20:54:22 -0400 Subject: [PATCH 07/10] Update data to be more detailed, forEach attempt --- data/assignments.js | 21 ++++++++++++--------- index.js | 24 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/data/assignments.js b/data/assignments.js index 4707985..ac4e2b0 100644 --- a/data/assignments.js +++ b/data/assignments.js @@ -1,17 +1,20 @@ -let assignments = [{ - assignment1: { - name: '', +let assignments = [ + { + name: 'Assignment1', completed: true }, - assignment2: { - name: '', + + { + name: 'Assignment2', completed: false }, - assignment3: { - name: '', + + { + name: 'Assignment3', completed: true - }, -}]; + } + +]; module.exports = { assignments diff --git a/index.js b/index.js index a1cdb26..361e93e 100644 --- a/index.js +++ b/index.js @@ -77,13 +77,31 @@ function loop(assignment) { console.log(allAssignments); */ - +/* let assigning = loop => { for (let i = 0; i < assignments.length; i++) { - return allAssignments.push(assignments[i]); + allAssignments.push(assignments[i]); }; } -console.log(assigning(), allAssignments); +*/ +console.log({ allAssignments }); +console.log(assignments); + +// FOR IN +/* +for (let i in assignments) { + const assignment = assignments[i] + console.log({ i }) +}; +*/ + +// forEach + +assignments.forEach((assignment) => { + allAssignments.push(assignments); +}) + + /** Filtering From 4e144e89581adc128d39cb0cf6bc878a6de63929 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 21:14:52 -0400 Subject: [PATCH 08/10] Playing with map method --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 361e93e..35bdae5 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,8 @@ const { assignments } = require('./data/assignments'); 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 */ -let allAssignments = [] + +// let allAssignments = [] /* function loop(assignment) { @@ -84,9 +85,10 @@ let assigning = loop => { }; } */ +/* console.log({ allAssignments }); console.log(assignments); - +*/ // FOR IN /* for (let i in assignments) { @@ -96,12 +98,18 @@ for (let i in assignments) { */ // forEach - +/* assignments.forEach((assignment) => { - allAssignments.push(assignments); + allAssignments.push(assignment); }) +console.log({ allAssignments }); +console.log(assignments); +*/ +let allAssignments = assignments.map((assignment) => assignment) +console.log(allAssignments); + /** Filtering From 568213023cbe03864d86bb75c589eda3eb21dd7e Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Wed, 22 Jul 2020 21:24:06 -0400 Subject: [PATCH 09/10] Show map function success --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 35bdae5..eccbdbb 100644 --- a/index.js +++ b/index.js @@ -107,15 +107,23 @@ assignments.forEach((assignment) => { console.log({ allAssignments }); console.log(assignments); */ +/* let allAssignments = assignments.map((assignment) => assignment) console.log(allAssignments); - +*/ /** - + Filtering - 5) Declare a new array named `completedAssignments`. Loop through the `assignments` array data using a for loop. Use a condition to only add to `allAssignments` where there are property values with `completed` of `true` - + 5) Declare a new array named `completedAssignments`. Loop through the `assignments` array data using a for loop. + Use a condition to only add to `completedAssignments` where there are property values with `completed` of `true` */ +let completedAssignment = assignments.map(completedAssignment => { + if (completedAssignment.completed === true) { + return completedAssignment + } +}) +console.log(completedAssignment); +console.log(assignments); From d2c60ca344b4bcdaa8836cdade41175bbe74e9a4 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 16:56:55 -0400 Subject: [PATCH 10/10] End of last night's work --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index eccbdbb..de33378 100644 --- a/index.js +++ b/index.js @@ -122,8 +122,17 @@ console.log(allAssignments); let completedAssignment = assignments.map(completedAssignment => { if (completedAssignment.completed === true) { return completedAssignment + } else { + return 'Not yet!' } }) -console.log(completedAssignment); +console.log({ completedAssignment }); console.log(assignments); +// Try a FILTER !! +/* +let completedAssignments = assignment.filter((assignment) => { + let completed = assignment; + return completed; +}) +*/ \ No newline at end of file