From 92e050d85f727c1f9e27cda9a2dd7c0af46fde65 Mon Sep 17 00:00:00 2001
From: Isah Jacob <Isahjacob0@gmail.com>
Date: Mon, 31 Oct 2022 21:34:26 +0100
Subject: [PATCH] I added parameters to the functions I converted the sum and
 multiplication parameters to an array I used lamda in order to multiply
 through the numbers

---
 08_calculator/calculator.js | 45 +++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/08_calculator/calculator.js b/08_calculator/calculator.js
index ded7068..c8d548f 100644
--- a/08_calculator/calculator.js
+++ b/08_calculator/calculator.js
@@ -6,10 +6,55 @@ function subtract (numberOne, numberTwo) {
 	return numberOne + numberTwo;; 
 }
 
+function sum (array) {
+  const result = Array.isArray(array) 
+  ? array.reduce((total, current) => total + current, 0): 0;
+  return result 
+}
+
+function multiply (array) {
+  const result = Array.isArray(array) 
+  ? array.reduce((total, current) => total * current, 1): 0;
+	return result 
+}
+
+function power(a, b) {
+  return a**b; 
+}
+
+
+function factorial(n) {
+ if (n === 0){
+   return 1;
+ }
+
+ let product = 1; 
+ 
+ for (let i = n; i > 0; i--){
+   product *= i;
+ }
+ return product; 
+}
 add(0, 0)
 add(2, 2)
 add(2,6)
 
+subtract(10,4)
+
+sum([])
+sum([7])
+sum([7, 11])
+sum([1,3,5,7,9])
+
+multiply([2,4])
+multiply([2,4,6,8,10,12,14])
+power(4,3)
+
+factorial(0)
+factorial(1)
+factorial(2)
+factorial(5)
+factorial(10)
 // Do not edit below this line
 module.exports = {
   add,