Skip to content

Commit 8d2cbda

Browse files
committed
🐛 fix: using reduce instead forEach
1 parent 36bca3d commit 8d2cbda

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

Maths/MidpointIntegration.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ function integralEvaluation (N, a, b, func) {
4141

4242
// Calculate the integral
4343
let result = h
44-
temp = 0
45-
pointsArray.forEach(point => {
46-
temp += point
47-
})
44+
temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0);
4845

4946
result *= temp
5047

Maths/SimpsonIntegration.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ function integralEvaluation (N, a, b, func) {
5454

5555
// Calculate the integral
5656
let result = h / 3
57-
temp = 0
58-
pointsArray.forEach(point => {
59-
temp += point
60-
})
57+
temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0);
6158

6259
result *= temp
6360

0 commit comments

Comments
 (0)