43 lines
661 B
JavaScript
43 lines
661 B
JavaScript
const add = function(a, b) {
|
|
return a + b;
|
|
};
|
|
|
|
const subtract = function(a, b) {
|
|
return a - b;
|
|
};
|
|
|
|
const sum = function(array) {
|
|
const output = array.reduce((total, value) => {
|
|
return total + value;
|
|
}, 0);
|
|
return output;
|
|
};
|
|
|
|
const multiply = function(array) {
|
|
const output = array.reduce((multiplification, value) => {
|
|
return multiplification * value;
|
|
}, 1);
|
|
return output;
|
|
};
|
|
|
|
const power = function(a, x) {
|
|
return 4 ** 3;
|
|
};
|
|
|
|
const factorial = function(a) {
|
|
if (a <= 1) {
|
|
return 1;
|
|
}
|
|
return a * factorial(a - 1);
|
|
};
|
|
|
|
// Do not edit below this line
|
|
module.exports = {
|
|
add,
|
|
subtract,
|
|
sum,
|
|
multiply,
|
|
power,
|
|
factorial
|
|
};
|