The current specification for the JavaScript Math object (namespace), according to MDN, comprises of 8 properties and 35 methods.
The extensive range of methods include a variety of Logarithmic Trigonometric and utility functions. Yet there is, at least in my eyes, a glaringly obvious omission.
There is min
and max
that can both take numerous arguments and return a single value, but where is the sum
function?
Instead we have to resort to coding this function ourselves, which is far from efficient.
Examples include:
function sum(...nums) {
return nums.reduce((tot, num) => tot + num);
}
// or
const sum = (...nums) => nums.reduce((tot, num) => tot + num);
We could polyfill but extending standard objects like Math is seldom a good decision.
I really would like to know why this method is missing, any suggestions?