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(firstVariable, secondVariable) {
|
||||
return firstVariable - secondVariable;
|
||||
};
|
||||
|
||||
const sum = function(myArray) {
|
||||
return myArray.reduce((runningTotal, myVariable) => runningTotal + myVariable, 0);
|
||||
};
|
||||
|
||||
const multiply = function(myArray) {
|
||||
return myArray.reduce((runningTotal, myVariable) => runningTotal * myVariable, 1);
|
||||
|
||||
};
|
||||
|
||||
const subtract = function() {
|
||||
|
||||
const power = function(baseNum, power) {
|
||||
return baseNum ** power;
|
||||
};
|
||||
|
||||
const sum = function() {
|
||||
|
||||
};
|
||||
|
||||
const multiply = function() {
|
||||
|
||||
};
|
||||
|
||||
const power = function() {
|
||||
|
||||
};
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue