| 788 | // mean, the mean of its first and last elements: it is not walked. |
| 789 | const m = rangeClosedFormOfOperand( |
| 790 | ops, |
| 791 | expression, |
| 792 | numericApproximation, |
| 793 | (x) => rangeMeanClosedForm(engine, x, numericApproximation) |
| 794 | ); |
| 795 | if (m !== undefined) return m; |
| 796 | // ONE walk of the data decides all three verdicts — an absent datum |
| 797 | // or empty input (`NaN`), a provably non-numeric datum (an error), or |
| 798 | // symbolic data (stay inert rather than fold a valueless symbol to |
| 799 | // `NaN`) — and feeds both paths below. See `collectData`. |
| 800 | const xs = collectData(engine, 'Mean', ops); |
| 801 | if (xs === null) return undefined; |
| 802 | if (!Array.isArray(xs)) return xs; |
| 803 | // Complex data: the arithmetic mean is linear over the complex |
| 804 | // numbers, so no convention has to be chosen and the answer is the |
| 805 | // complex mean — `Mean([1, 1+2i])` is `1 + i`. The boxed accumulation |
| 806 | // serves both paths: it is exact on exact data, and `.N()` |
| 807 | // numericizes what it returns. |
| 808 | // |