Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions data/grades.js
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 22 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -50,4 +58,15 @@
Replace `null` below with the use of `reduce`

*/
gradeTotal = null

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(titosTotal)