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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: optimized AverageMean.js by removing redundant comments and unne…
…cessary operations.
  • Loading branch information
HRIDYANSHU054 committed Oct 10, 2024
commit 252ff106b3a66f26a066cc94d2e805f397930307
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 calculates the sum of all values in the 'nums' array using reduce method.
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 / nums.length, 0)
}

export { mean }