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
40 changes: 40 additions & 0 deletions data/grades.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
let grades = [{
assignmentName: 'Assignment01',
studentName: 'Seven',
score: 86
}, {
assignmentName: 'Assignment02',
studentName: 'Geneva',
score: 71
}, {
assignmentName: 'Assignment03',
studentName: 'Seven',
score: 90
}, {
assignmentName: 'Assignment04',
studentName: 'Geneva',
score: 99
}, {
assignmentName: 'Assignment05',
studentName: 'Seven',
score: 62
}, {
assignmentName: 'Assignment06',
studentName: 'Geneva',
score: 87
}];












module.exports = {
grades
}
70 changes: 57 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,68 @@

*/

/**
/**

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 { grades } = require('./data/grades')

/*
let gradeTotal = 0

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
}
*/

*/
const gradeTotal = 0


/**

Using reduce

3) Use Array reduce to do the same total calculation logic
// forEach
/*
let gradeTotal = 0;

Replace `null` below with the use of `reduce`
gradeTotal.forEach(grade => grades.score += grades.score)
*/
/*
gradeTotal = 0
grades.forEach(grade => {
gradeTotal += grade.score
})
*/

//

/**

*/
gradeTotal = null
Using reduce
3) Use Array reduce to do the same total calculation logic
Replace `null` below with the use of `reduce`

*/



gradeTotal = grades.reduce((total, grade) => {
console.log(total, grade)
return total + grade.score
}, 0)

console.log(gradeTotal)