2023-06-19 16:55:57 -07:00
|
|
|
const add = function (...numbers) {
|
|
|
|
return numbers.reduce((res, cur) => res + cur, 0)
|
|
|
|
}
|
2017-09-20 16:04:46 -07:00
|
|
|
|
2023-06-19 16:55:57 -07:00
|
|
|
const subtract = function (...numbers) {
|
|
|
|
return numbers.reduce((res, cur) => res - cur)
|
|
|
|
}
|
2017-09-20 16:04:46 -07:00
|
|
|
|
2023-06-19 16:55:57 -07:00
|
|
|
const sum = function (numbers) {
|
|
|
|
return add(...numbers)
|
|
|
|
}
|
2017-09-20 16:04:46 -07:00
|
|
|
|
2023-06-19 16:55:57 -07:00
|
|
|
const multiply = function (...numbers) {
|
|
|
|
return numbers.reduce((res, cur) => res * cur)
|
|
|
|
}
|
2021-03-02 18:13:24 -08:00
|
|
|
|
2023-06-19 16:55:57 -07:00
|
|
|
const power = function (...numbers) {
|
|
|
|
return numbers.reduce((res, cur) => res ** cur)
|
|
|
|
}
|
2017-09-20 16:04:46 -07:00
|
|
|
|
2023-06-19 16:55:57 -07:00
|
|
|
const factorial = function (number) {
|
|
|
|
if (number < 0) {
|
|
|
|
return -1
|
|
|
|
} else if (number === 0) {
|
|
|
|
return 1
|
|
|
|
} else {
|
|
|
|
return number * factorial(number - 1)
|
|
|
|
}
|
|
|
|
}
|
2017-09-20 16:04:46 -07:00
|
|
|
|
2021-09-11 15:18:19 -07:00
|
|
|
// Do not edit below this line
|
2017-09-20 16:04:46 -07:00
|
|
|
module.exports = {
|
2021-03-02 18:13:24 -08:00
|
|
|
add,
|
|
|
|
subtract,
|
|
|
|
sum,
|
|
|
|
multiply,
|
|
|
|
power,
|
2023-06-19 16:55:57 -07:00
|
|
|
factorial,
|
|
|
|
}
|