From 0b9e923cd4960096af05016c7b61ebf3a98ff8ef Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 23 Jul 2020 19:05:12 -0400 Subject: [PATCH 1/5] Answer to problem 01 --- data/grades.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 data/grades.js diff --git a/data/grades.js b/data/grades.js new file mode 100644 index 0000000..21136d2 --- /dev/null +++ b/data/grades.js @@ -0,0 +1,30 @@ +let grades = [ + { + assignmentName: 'Assignment 01', + studentName: 'Tito', + score: '85', + }, + { + assignmentName: 'Assignment 02', + studentName: 'Ralph', + score: '74', + }, + { + assignmentName: 'Assignment 03', + studentName: 'Ralph', + score: '90', + }, + { + assignmentName: 'Assignment 03', + studentName: 'Tito', + score: '95', + }, + { + assignmentName: 'Assignment 04', + studentName: 'Ralph', + score: '85', + }, +] +module.exports = { + grades +} \ No newline at end of file From 647a170e51544dcadedd7d69bd177a7022c124a5 Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 23 Jul 2020 19:11:11 -0400 Subject: [PATCH 2/5] Change scores to numbers not strings --- data/grades.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data/grades.js b/data/grades.js index 21136d2..3140e21 100644 --- a/data/grades.js +++ b/data/grades.js @@ -2,27 +2,27 @@ let grades = [ { assignmentName: 'Assignment 01', studentName: 'Tito', - score: '85', + score: 85, }, { assignmentName: 'Assignment 02', studentName: 'Ralph', - score: '74', + score: 74, }, { assignmentName: 'Assignment 03', studentName: 'Ralph', - score: '90', + score: 90, }, { assignmentName: 'Assignment 03', studentName: 'Tito', - score: '95', + score: 95, }, { assignmentName: 'Assignment 04', studentName: 'Ralph', - score: '85', + score: 85, }, ] module.exports = { From 015594adba2f2c20ad9dd7cadeb0a534d14a49d2 Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 23 Jul 2020 19:43:33 -0400 Subject: [PATCH 3/5] Answer to problem 02 --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 856a122..d4094e8 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,8 @@ - Use 2 distinct student names */ - +const { grades } = require('./data/grades') +console.log({grades}) /** Looping using your preferred looping syntax and updating a shared variable @@ -38,9 +39,16 @@ Update `gradeTotal` so it increases value for each item in the array */ - const gradeTotal = 0 +let gradeTotal = 0 + +for (const index in grades) { + const grade = grades[index] + gradeTotal += grade.score +} +//expect gradeTotal = 429 +console.log({gradeTotal}) /** Using reduce From e042f2ff34222fa048b2930588cfac293e114d23 Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 23 Jul 2020 20:27:50 -0400 Subject: [PATCH 4/5] Answer problem 03 --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d4094e8..b4fc3fb 100644 --- a/index.js +++ b/index.js @@ -58,4 +58,8 @@ console.log({gradeTotal}) Replace `null` below with the use of `reduce` */ - gradeTotal = null + gradeTotal = grades.reduce((total, grade) => { + console.log(total, grade) + return total + grade.score + }, 0) +console.log(gradeTotal) \ No newline at end of file From 2c99eaae6a03a262443849d3e1db0a40ddc9b23f Mon Sep 17 00:00:00 2001 From: Jessica Date: Thu, 23 Jul 2020 20:45:34 -0400 Subject: [PATCH 5/5] Total of Tito's grades --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b4fc3fb..c92ea9c 100644 --- a/index.js +++ b/index.js @@ -58,8 +58,15 @@ console.log({gradeTotal}) Replace `null` below with the use of `reduce` */ - gradeTotal = grades.reduce((total, grade) => { + +let titosGrades = grades.filter((grade) => { + return grade.studentName === 'Tito' +}) +console.log({titosGrades}) + + titosTotal = titosGrades.reduce((total, grade) => { console.log(total, grade) return total + grade.score }, 0) -console.log(gradeTotal) \ No newline at end of file + +console.log(titosTotal) \ No newline at end of file