Update calculator.js
This commit is contained in:
parent
cc479b5e70
commit
200e4c157b
|
@ -1,25 +1,28 @@
|
|||
function add () {
|
||||
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function subtract () {
|
||||
|
||||
function subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function sum () {
|
||||
|
||||
function sum(array) {
|
||||
return array.reduce((current, total) => total + current, 0);
|
||||
}
|
||||
|
||||
function multiply () {
|
||||
|
||||
function multiply(array) {
|
||||
return array.length
|
||||
? array.reduce((accumulator, nextItem) => accumulator * nextItem)
|
||||
: 0;
|
||||
}
|
||||
|
||||
function power() {
|
||||
|
||||
function power(a, b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
|
||||
function factorial() {
|
||||
|
||||
function factorial(n) {
|
||||
if (n === 0) {return 1};
|
||||
return n * factorial(n -1)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in New Issue