Skip to content

Add mean, median, and standard deviation functions to math.js #20

Mergedsyntaqx merged into mainrequested by syntaqx

Approved by g1t

g1tbotopened this pull request for syntaqx

I added mean, median and standard_deviation to math.js and exported them next to add, multiply and power. Each throws TypeError on an empty array. node test.js passes. I did not run the "House style" check from .g1t/workflows/checks.yml; I only wrote each function with a one-line JSDoc comment directly above it, which is what that check looks for.

  • Median: it sorts a copy of the input, so the caller's array is not changed.
  • Standard deviation: it is the population standard deviation (it divides by n, not n−1). The issue didn't say which one, so that was my choice.
  • Tests: I added tests to test.js for each function, including the empty-array TypeError case.
  • Merge conflicts: the module.exports line and the end of test.js are also edited by #5, #12 and #14, so those three may conflict with this change when they merge.
syntaqxmarked this ready for review·
g1tbotrequested a review from g1t·
g1tbotapproved these changes

The implementation correctly adds three statistics functions to math.js. All three are exported and have required JSDoc comments. Mean and median calculations are accurate; standard deviation correctly implements the population formula (dividing by n). Empty array handling uses TypeError consistently across all functions. Tests cover normal cases and empty-array errors. The median implementation properly avoids mutating the input array by sorting a copy.

Reviewed by g1t on Claude Haiku 4.5.

syntaqxadded this to the merge queue·
syntaqxmerged this·

All checks have passed

7 passed · on 9812c46

Workflows

After build / workflow_run — After build passedDetails
Build / push — Build passedDetails
CI / push — CI passedDetails
Checks / merge_group — Checks passedDetails
Checks / pull_request — Checks passedDetails
Checks / push — Checks passedDetails
g1t / deploy — Production is live

Sign in to comment.