2021-03-03 15:13:24 +13:00
|
|
|
const add = function() {
|
2025-02-26 09:55:45 +09:00
|
|
|
console.log(arguments)
|
|
|
|
|
let add = 0;
|
|
|
|
|
for (i = 0; i < arguments.length; i++) {
|
|
|
|
|
add += arguments[i]
|
|
|
|
|
}
|
|
|
|
|
return add
|
2021-03-03 15:13:24 +13:00
|
|
|
};
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-03-03 15:13:24 +13:00
|
|
|
const subtract = function() {
|
2025-02-26 09:55:45 +09:00
|
|
|
console.log(arguments)
|
|
|
|
|
return arguments[0] - arguments[1]
|
2021-03-03 15:13:24 +13:00
|
|
|
};
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-03-03 15:13:24 +13:00
|
|
|
const sum = function() {
|
2025-02-26 09:55:45 +09:00
|
|
|
console.log(arguments)
|
|
|
|
|
return arguments[0].reduce((total, arg) => total + arg,0)
|
2021-03-03 15:13:24 +13:00
|
|
|
};
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-03-03 15:13:24 +13:00
|
|
|
const multiply = function() {
|
2025-02-26 09:55:45 +09:00
|
|
|
console.log(arguments)
|
|
|
|
|
return arguments[0].reduce((total, arg) => total * arg,1)
|
2021-03-03 15:13:24 +13:00
|
|
|
|
2021-05-18 11:43:23 +12:00
|
|
|
};
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-03-03 15:13:24 +13:00
|
|
|
const power = function() {
|
2025-02-26 09:55:45 +09:00
|
|
|
console.log(arguments)
|
|
|
|
|
return arguments[0] ** arguments[1]
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-03-03 15:13:24 +13:00
|
|
|
};
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-03-03 15:13:24 +13:00
|
|
|
const factorial = function() {
|
2025-02-26 09:55:45 +09:00
|
|
|
console.log(arguments)
|
|
|
|
|
let factorial = 1;
|
|
|
|
|
for (i=1; i<= arguments[0]; i++) {
|
|
|
|
|
factorial *= i
|
|
|
|
|
}
|
|
|
|
|
return factorial;
|
2021-03-03 15:13:24 +13:00
|
|
|
};
|
2017-09-20 19:04:46 -04:00
|
|
|
|
2021-09-11 16:18:19 -06:00
|
|
|
// Do not edit below this line
|
2017-09-20 19:04:46 -04:00
|
|
|
module.exports = {
|
2021-03-03 15:13:24 +13:00
|
|
|
add,
|
|
|
|
|
subtract,
|
|
|
|
|
sum,
|
|
|
|
|
multiply,
|
|
|
|
|
power,
|
|
|
|
|
factorial
|
|
|
|
|
};
|