From 1aa03a229a70137fa3ec0d222fafdc496d4ae6c3 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 18:53:38 -0400 Subject: [PATCH 1/8] First commit including data and export --- data/grades.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 data/grades.js diff --git a/data/grades.js b/data/grades.js new file mode 100644 index 0000000..89600e9 --- /dev/null +++ b/data/grades.js @@ -0,0 +1,40 @@ +let grades = [{ + assignmentName: 'Assignment01', + studentName: 'Seven', + score: 86 +}, { + assignmentName: 'Assignment02', + studentName: 'Spencer', + score: 71 +}, { + assignmentName: 'Assignment03', + studentName: 'John', + score: 90 +}, { + assignmentName: 'Assignment04', + studentName: 'Geneva', + score: 99 +}, { + assignmentName: 'Assignment05', + studentName: 'Derrik', + score: 62 +}, { + assignmentName: 'Assignment06', + studentName: 'Paul', + score: 87 +}]; + + + + + + + + + + + + +module.exports = { + grades +} \ No newline at end of file From d7e1b961b0843910f19e089ebf75736c4611d842 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 18:57:18 -0400 Subject: [PATCH 2/8] Change to limit of two student names --- data/grades.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/grades.js b/data/grades.js index 89600e9..b225195 100644 --- a/data/grades.js +++ b/data/grades.js @@ -4,11 +4,11 @@ let grades = [{ score: 86 }, { assignmentName: 'Assignment02', - studentName: 'Spencer', + studentName: 'Geneva', score: 71 }, { assignmentName: 'Assignment03', - studentName: 'John', + studentName: 'Seven', score: 90 }, { assignmentName: 'Assignment04', @@ -16,11 +16,11 @@ let grades = [{ score: 99 }, { assignmentName: 'Assignment05', - studentName: 'Derrik', + studentName: 'Seven', score: 62 }, { assignmentName: 'Assignment06', - studentName: 'Paul', + studentName: 'Geneva', score: 87 }]; From 2d03a20b78bae16f955d36362ef8ce1358eb2653 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 19:04:14 -0400 Subject: [PATCH 3/8] For loop attempt --- index.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 856a122..f378580 100644 --- a/index.js +++ b/index.js @@ -30,24 +30,27 @@ */ - /** +/** - Looping using your preferred looping syntax and updating a shared variable + Looping using your preferred looping syntax and updating a shared variable - 2) Loop through the grades data using a for loop. - Update `gradeTotal` so it increases value for each item in the array + 2) Loop through the grades data using a for loop. + Update `gradeTotal` so it increases value for each item in the array - */ - const gradeTotal = 0 +*/ +const gradeTotal = 0 +for (let i = 0; i < grades.length; i++) { + return gradeTotal.push(grades[i] + grades[i]) +} - /** +/** - Using reduce + Using reduce - 3) Use Array reduce to do the same total calculation logic + 3) Use Array reduce to do the same total calculation logic - Replace `null` below with the use of `reduce` + Replace `null` below with the use of `reduce` - */ - gradeTotal = null + */ +gradeTotal = null From 16299830a51348df260df1178b5d4e4e0973c01e Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 19:17:21 -0400 Subject: [PATCH 4/8] Container for loop, no errors yet --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f378580..0dff861 100644 --- a/index.js +++ b/index.js @@ -38,12 +38,15 @@ Update `gradeTotal` so it increases value for each item in the array */ -const gradeTotal = 0 +const { grades } = require('./data/grades') -for (let i = 0; i < grades.length; i++) { - return gradeTotal.push(grades[i] + grades[i]) -} +let gradeTotal = 0 +function makeGrades(grading) { + for (let i = 0; i < grades.length; i++) { + return gradeTotal.push(grades[i] + grades[i]) + } +} /** Using reduce From 8b9acd03eac095819709eb893f6cd0bce5a40031 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 19:32:00 -0400 Subject: [PATCH 5/8] Non-adding attempt, work in progress --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0dff861..7d7dfcc 100644 --- a/index.js +++ b/index.js @@ -44,9 +44,11 @@ let gradeTotal = 0 function makeGrades(grading) { for (let i = 0; i < grades.length; i++) { - return gradeTotal.push(grades[i] + grades[i]) + gradeTotal.push(grades.score + grades.score) } } + +console.log(grades, gradeTotal) /** Using reduce From ece883278683e6cf63ba95e2b91ad46556f4fc8c Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 19:34:48 -0400 Subject: [PATCH 6/8] Minor change, still unworking --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7d7dfcc..66e80f9 100644 --- a/index.js +++ b/index.js @@ -44,7 +44,7 @@ let gradeTotal = 0 function makeGrades(grading) { for (let i = 0; i < grades.length; i++) { - gradeTotal.push(grades.score + grades.score) + gradeTotal = grades.score += grades[i] } } From 1e6e823184173a140d1690e5bb4d977d43812d62 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 20:19:11 -0400 Subject: [PATCH 7/8] Not working, many tries --- index.js | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 66e80f9..3224229 100644 --- a/index.js +++ b/index.js @@ -40,22 +40,56 @@ */ const { grades } = require('./data/grades') +/* let gradeTotal = 0 -function makeGrades(grading) { - for (let i = 0; i < grades.length; i++) { - gradeTotal = grades.score += grades[i] - } +for (let i = 0; i < grades.length; i++) { + gradeTotal = grades.score += grades[i] } + console.log(grades, gradeTotal) + +*/ + +// for In +/* +for (const index in grades) { + const { score } = grades[index] + console.log({ score }) + gradeTotal += score +} +*/ + + + + +// forEach +/* +let gradeTotal = 0; + +gradeTotal.forEach(grade => grades.score += grades.score) +*/ +/* +gradeTotal = 0 +grades.forEach(grade => { + gradeTotal += grade.score +}) +*/ + +// + /** Using reduce - 3) Use Array reduce to do the same total calculation logic - - Replace `null` below with the use of `reduce` + Replace `null` below with the use of `reduce` */ -gradeTotal = null + + + +gradeTotal = grades.reduce((total, grade) => { + grades.score += grades.score + console.log(total, grade); +}, 0) From 66e9c85a0a5deac2c0d2694a6350e0d8a59447f9 Mon Sep 17 00:00:00 2001 From: Nick Lavery Date: Thu, 23 Jul 2020 20:27:12 -0400 Subject: [PATCH 8/8] Fixed, amazing how small things cause the biggest problems --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3224229..a786e23 100644 --- a/index.js +++ b/index.js @@ -90,6 +90,8 @@ grades.forEach(grade => { gradeTotal = grades.reduce((total, grade) => { - grades.score += grades.score - console.log(total, grade); + console.log(total, grade) + return total + grade.score }, 0) + +console.log(gradeTotal) \ No newline at end of file