Skip to content

Commit

Permalink
docs: fixed misleading comment about the array method (forEach instea…
Browse files Browse the repository at this point in the history
…d of reduce) used in AverageMean.js (#1727)

* docs: fixed misleading comment about the array method (forEach instead of reduce) used in AverageMean.js

* fix: optimized AverageMean.js by removing redundant comments and unnecessary operations.

* Update Maths/AverageMean.js

Co-authored-by: Lars Müller <[email protected]>

---------

Co-authored-by: Hridyanshu7 <[email protected]>
Co-authored-by: Lars Müller <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent ff314a2 commit 55ff0ad
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions Maths/AverageMean.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const mean = (nums) => {
throw new TypeError('Invalid Input')
}

// This loop sums all values in the 'nums' array using forEach loop
const sum = nums.reduce((sum, cur) => sum + cur, 0)

// Divide sum by the length of the 'nums' array.
return sum / nums.length
return nums.reduce((sum, cur) => sum + cur, 0) / nums.length
}

export { mean }

0 comments on commit 55ff0ad

Please sign in to comment.