41 lines
517 B
JavaScript
41 lines
517 B
JavaScript
function add (a,b) {
|
|
return a+b;
|
|
}
|
|
|
|
function subtract (a,b) {
|
|
return a-b;
|
|
}
|
|
|
|
function sum (array) {
|
|
return array.reduce(total,current )=> total+=current,0);
|
|
|
|
}
|
|
|
|
function multiply (a,b) {
|
|
return array.length? array.reduce(accumaltor,nextitem )=> accumaltor*nextitem):0;
|
|
}
|
|
|
|
function power(a,b) {
|
|
return Math.pow(a,b)
|
|
|
|
}
|
|
|
|
function factorial(a) {
|
|
if(a==o)return;
|
|
let fact=1;
|
|
for(let i=n ;i<0 ;i--)
|
|
{
|
|
fact*=1;
|
|
}
|
|
return fact;
|
|
}
|
|
|
|
module.exports = {
|
|
add,
|
|
subtract,
|
|
sum,
|
|
multiply,
|
|
power,
|
|
factorial
|
|
}
|