solution 5
This commit is contained in:
parent
ae2ab746be
commit
b98b40c614
|
@ -1,27 +1,63 @@
|
||||||
const add = function() {
|
const add = function(num1, num2) {
|
||||||
|
total = num1 + num2;
|
||||||
|
console.log(total);
|
||||||
|
return total;
|
||||||
};
|
};
|
||||||
|
|
||||||
const subtract = function() {
|
const subtract = function(num1, num2) {
|
||||||
|
total = num1 - num2;
|
||||||
|
console.log(total);
|
||||||
|
return total;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sum = function() {
|
const sum = function(arg) {
|
||||||
|
const array = arg;
|
||||||
|
console.log(array);
|
||||||
|
let total = 0;
|
||||||
|
for (i = 0; i < array.length; i++) {
|
||||||
|
total += array[i];
|
||||||
|
}
|
||||||
|
console.log(total);
|
||||||
|
return total;
|
||||||
};
|
};
|
||||||
|
|
||||||
const multiply = function() {
|
const multiply = function(arg) {
|
||||||
|
const array = arg;
|
||||||
|
console.log(array);
|
||||||
|
let total = 1;
|
||||||
|
for (i = 0; i < array.length; i++) {
|
||||||
|
total = total * array[i];
|
||||||
|
}
|
||||||
|
console.log(total);
|
||||||
|
return total;
|
||||||
};
|
};
|
||||||
|
//multiply([-4,4])
|
||||||
|
|
||||||
const power = function() {
|
const power = function(num, factor) {
|
||||||
|
total = Math.pow(num, factor);
|
||||||
|
|
||||||
|
console.log(total);
|
||||||
|
return total;
|
||||||
};
|
};
|
||||||
|
// power(2,2)
|
||||||
|
|
||||||
const factorial = function() {
|
const factorial = function(num) {
|
||||||
|
if (num === 0 || num === 1) {
|
||||||
|
console.log('1');
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
for (var i = num - 1; i >= 1; i--) {
|
||||||
|
num *= i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(num);
|
||||||
|
return num;
|
||||||
};
|
};
|
||||||
|
factorial(6);
|
||||||
|
|
||||||
|
//add(2, 4);
|
||||||
|
//subtract ( 1, -10)
|
||||||
|
//sum([ 1, 3, 2 ]);
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
module.exports = {
|
module.exports = {
|
||||||
add,
|
add,
|
||||||
|
|
Loading…
Reference in New Issue