mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
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:
@ -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 }
|
||||
|
Reference in New Issue
Block a user