completed Calculator exercise
This commit is contained in:
parent
9577d2bd5d
commit
707a589009
|
@ -1,25 +1,32 @@
|
||||||
const add = function() {
|
const add = function(firstVariable, secondVariable) {
|
||||||
|
return firstVariable + secondVariable;
|
||||||
};
|
};
|
||||||
|
|
||||||
const subtract = function() {
|
const subtract = function(firstVariable, secondVariable) {
|
||||||
|
return firstVariable - secondVariable;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sum = function() {
|
const sum = function(myArray) {
|
||||||
|
return myArray.reduce((runningTotal, myVariable) => runningTotal + myVariable, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const multiply = function() {
|
const multiply = function(myArray) {
|
||||||
|
return myArray.reduce((runningTotal, myVariable) => runningTotal * myVariable, 1);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const power = function() {
|
const power = function(baseNum, power) {
|
||||||
|
return baseNum ** power;
|
||||||
};
|
};
|
||||||
|
|
||||||
const factorial = function() {
|
const factorial = function(myVariable) {
|
||||||
|
if (myVariable < 0) {
|
||||||
|
return -1;
|
||||||
|
} else if (myVariable === 0) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return (myVariable * factorial(myVariable - 1))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
|
|
Loading…
Reference in New Issue