Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2024
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 }