2017-12-15 10:56:14 -08:00
|
|
|
function add(a, b) {
|
|
|
|
return a + b;
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:56:14 -08:00
|
|
|
function subtract(a, b) {
|
|
|
|
return a - b;
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:56:14 -08:00
|
|
|
function sum(array) {
|
|
|
|
return array.reduce((current, total) => total + current, 0);
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:56:14 -08:00
|
|
|
function multiply(array) {
|
|
|
|
return array.reduce((current, total) => total * current, 1);
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:56:14 -08:00
|
|
|
function power(a, b) {
|
|
|
|
return Math.pow(a, b);
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:56:14 -08:00
|
|
|
function factorial(n) {
|
2018-01-03 09:10:49 -08:00
|
|
|
if (n===0){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return n * factorial (n-1);
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-12-15 10:56:14 -08:00
|
|
|
add,
|
|
|
|
subtract,
|
|
|
|
sum,
|
|
|
|
multiply,
|
|
|
|
power,
|
|
|
|
factorial
|
|
|
|
};
|