Very simple (stupid?) question: are there built-in arithmetic functions in JS such as addition or multiplication?
For example some imaginary Math.add which can be used like this:
[ 3, 1, 2 ].reduce( Math.add ) // 6
hi lucifer63 the function you are asking for like add, sum might not be available but that you can do by the operator but for the little complex operation we do have
Math.round(4.7);
Math.PI;
Math.pow(8, 2);
Math.sqrt(64);if you check out the w3school Link you can find more math function's which are also very usefull
const add = (x, y) => x + y; [ 3, 1, 2 ].reduce( add ); can be your solution because using different Math library function to create an add (sum) might not be suitable (or even possible)
(a,b)=>a+b,(a,b)=>a*betcconst addNumbers = (...arr) => arr.reduce((a, b) => a + b)And call withaddNumbers(1,2,3,4)