From 08066efddc88d6215816f138315300d0f0b5c21d Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:08:27 -0400 Subject: [PATCH 1/7] npm audit fix --- package-lock.json | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d451a9..e0f6e26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2873,13 +2873,10 @@ } }, "node_modules/json5": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", - "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, - "dependencies": { - "minimist": "^1.2.5" - }, "bin": { "json5": "lib/cli.js" }, @@ -3022,9 +3019,9 @@ } }, "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -3033,12 +3030,6 @@ "node": "*" } }, - "node_modules/minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -6180,13 +6171,10 @@ "dev": true }, "json5": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", - "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true }, "kleur": { "version": "3.0.3", @@ -6290,20 +6278,14 @@ "dev": true }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, - "minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", From dcea47c36902db9ac4c1709fc61b3f300a209f12 Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:15:03 -0400 Subject: [PATCH 2/7] console.log the array / call the function --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3bb4d07..5a5880d 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,13 @@ * Depending on the operation, either add up all of the numbers or subtract all of the numbers, from left to right. * @returns {number} The result of either adding all numbers or subtracting all numbers, depending on the arguments added to the command line. */ -function calculator() {} +function calculator() { + + console.log(process.argv) + +} + +calculator() // Don't change anything below this line. module.exports = calculator; From 397e12ba8ac4ecb52297cc119682f5dcff2b6e04 Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:21:24 -0400 Subject: [PATCH 3/7] first two error handling --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 5a5880d..ef52305 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,12 @@ function calculator() { console.log(process.argv) + if (process.argv.length < 3) { + return `No operation provided...` + } else if (process.argv.length < 4) { + return `No numbers provided...` + } + } calculator() From 9c52adcc976c811f70c52463da6c8f0685587dee Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:23:53 -0400 Subject: [PATCH 4/7] variable declaration --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index ef52305..cfa381a 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,10 @@ function calculator() { console.log(process.argv) + let operation = process.argv[2]; + let operationArray = [] + let result; + if (process.argv.length < 3) { return `No operation provided...` } else if (process.argv.length < 4) { From 9c881390cf75b9cc122da356759fe6df6313562a Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:27:39 -0400 Subject: [PATCH 5/7] plus operation added --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cfa381a..1d22428 100644 --- a/index.js +++ b/index.js @@ -17,9 +17,16 @@ function calculator() { } else if (process.argv.length < 4) { return `No numbers provided...` } + else if (operation === "plus") { + for (let i = 3; i < process.argv.length; i++) { + let num = process.argv[i] + operationArray.push(num) + result = operationArray.reduce((a, b) => Number(a) + Number(b)) + } + return result + } } - calculator() // Don't change anything below this line. From 3e080b0533f732a6098626d0648562133f6435f8 Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:30:38 -0400 Subject: [PATCH 6/7] added minus operation --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 1d22428..d196abb 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,14 @@ function calculator() { result = operationArray.reduce((a, b) => Number(a) + Number(b)) } return result + } + else if (operation === "minus") { + for (let i = 3; i < process.argv.length; i++) { + let num = process.argv[i] + operationArray.push(num) + result = operationArray.reduce((a, b) => Number(a) - Number(b)) + } + return result } } From 83e3265781e15b48afaff2544097583ae768fe0a Mon Sep 17 00:00:00 2001 From: Kenneth-Parker Date: Wed, 3 May 2023 21:35:19 -0400 Subject: [PATCH 7/7] final error handlinig added --- index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d196abb..0e102a0 100644 --- a/index.js +++ b/index.js @@ -8,15 +8,15 @@ function calculator() { console.log(process.argv) - let operation = process.argv[2]; + let operation = process.argv[2] let operationArray = [] - let result; - + let result + // error handling if (process.argv.length < 3) { return `No operation provided...` } else if (process.argv.length < 4) { return `No numbers provided...` - } + } // plus else if (operation === "plus") { for (let i = 3; i < process.argv.length; i++) { let num = process.argv[i] @@ -24,7 +24,7 @@ function calculator() { result = operationArray.reduce((a, b) => Number(a) + Number(b)) } return result - } + } // minus else if (operation === "minus") { for (let i = 3; i < process.argv.length; i++) { let num = process.argv[i] @@ -32,6 +32,9 @@ function calculator() { result = operationArray.reduce((a, b) => Number(a) - Number(b)) } return result + } // final error handling + else if (operation !== "plus" || "minus") { + return `Invalid operation: ${operation}` } }