docs: fixed misleading comment about the array method (forEach instead 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 <34514239+appgurueu@users.noreply.github.com>

---------

Co-authored-by: Hridyanshu7 <himank7794@gmail.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
Hridyanshu
2024-10-16 23:52:31 +05:30
committed by GitHub
parent ff314a2bed
commit 55ff0ade85

View File

@ -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 }