rwaldron / proposal-math-extensions

ES Math Extensions
61 stars 7 forks source link

[Suggestion] Math.mean and Math.roundBy #13

Open fega opened 5 years ago

fega commented 5 years ago

Hello, I really like this proposal, and I'd like two suggestions

Math.mean([1,2,3]) // 2

Math.roundBy(100.1234, 2) // 100.12

I'm proposing a separated method for round, since I think that Math.round could lead to breaking changes

Crissov commented 5 years ago

Means

I support the addition of a buildin function for the arithmetic mean, but I think mean() is not the best name for it, because there are other useful means as well, and even a generalized mean. Therefore, we should have all of them:

Since you might want to support truncated means or weighted means out of the box as well, it might make sense to expect the arguments args as an array (or similar iteratable): mean(int = 1, args = [], trunc = 0, weight = []).

Other

Other functions working on a set of values would make sense as well:

Rounding

For rounding #11, I would prefer a module as a second parameter that the result must be a multiple of: mround(1.2345, 0.01) = 1.23.

Rudxain commented 2 years ago

Also Standard Deviation may be a good idea