From 75072a3ba48a969a691624ece33d091d45627aec Mon Sep 17 00:00:00 2001 From: BrianYoung1223 Date: Sun, 30 Apr 2023 21:15:52 -0400 Subject: [PATCH 1/2] I tried my best on this rainy Sunday i been working on this lab all day, couldnt crack it --- index.js | 40 +++++++++++++++++++++++++++++++++++++++- package-lock.json | 44 +++++++++++++------------------------------- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 3bb4d07..4dcfadd 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,45 @@ * 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() { + theOperator = process.argv[2]; + if (theOperator !== ("plus" || "minus")){ + return (`Invalid operation: ${theOperator}`) + } +} + + // console.log (process.argv[2]) + if (firstStep !== "plus" || firstStep !== "minus"){ + return `Invalid operation: ${process.argv[2]}` + } + let firstStep = process.argv[2] + if (firstStep === undefined){ + return "No operation provided..." + } + if (firstStep !== "plus" || firstStep !== "minus"){ + return `Invalid operation: ${process.argv[2]}` +} + let numbers = process.argv.slice(3) + if (numbers.length === 0){ + return "No numbers provided..." + } + if (typeof Number (numbers[0]) !== `number`){ + return "No numbers provided..." + } + + console.log (process.argv[2]); + +//console.log (calculator( parseInt(`${process.argv[3]}`) + parseInt(`${process.argv[4]}`))); + // console.log(process.argv[2]) // Don't change anything below this line. module.exports = calculator; + 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 85da4c285e7af87ad36c59cb944b3d52fa4f09ca Mon Sep 17 00:00:00 2001 From: BrianYoung1223 Date: Tue, 2 May 2023 23:29:53 -0400 Subject: [PATCH 2/2] The Brian Young Machine Lab --- index.js | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index 4dcfadd..477dee0 100644 --- a/index.js +++ b/index.js @@ -9,40 +9,33 @@ +function calculator(){ + let theOperator = process.argv[2] // + let sum = 0 + if (!theOperator) { //Deteremine if this variable does not contains "theOperator"? by signify with the "!" operator. + return "No operation provided..."; //Determined that there was not "theOperator" thus returning the "No operation provided.."statement! + } else if (theOperator !== "plus" && theOperator != "minus"){ // If no mathmatical expression is provided either "plus" or "minus". + return `Invalid operation: ${theOperator}`; // Return the response of "Invalid operator :" + my variable of "theOperator" I used `string interpelation` in order to combine my return values. + } + let numbers = process.argv.slice(3); //Created "numbers" variable equal to my [3] index of my array by creating new copy of to iterate by using the .slice() method becuase we know the "numbers" start at that index of the array! + if (numbers.length === 0){ // if != No number is provided through length of the array! + return "No numbers provided..." // Then return the response of "No numbers provided..." + } + + for(let num of numbers){ // While looping through the array of numbers + console.log (num) + if (theOperator === "plus"){ // Checking if "theOperator" is equal to "plus" + return sum = numbers.reduce((preiousVal, currentVal) => Number(preiousVal) + Number (currentVal)); // With the .reduce method I used to take two values from the prevVal and currentVal and manipulate my array to add the values! + } + } -function calculator() { - theOperator = process.argv[2]; - if (theOperator !== ("plus" || "minus")){ - return (`Invalid operation: ${theOperator}`) - } -} - - // console.log (process.argv[2]) - if (firstStep !== "plus" || firstStep !== "minus"){ - return `Invalid operation: ${process.argv[2]}` - } - let firstStep = process.argv[2] - if (firstStep === undefined){ - return "No operation provided..." - } - if (firstStep !== "plus" || firstStep !== "minus"){ - return `Invalid operation: ${process.argv[2]}` -} - let numbers = process.argv.slice(3) - if (numbers.length === 0){ - return "No numbers provided..." - } - if (typeof Number (numbers[0]) !== `number`){ - return "No numbers provided..." - } - - console.log (process.argv[2]); - -//console.log (calculator( parseInt(`${process.argv[3]}`) + parseInt(`${process.argv[4]}`))); - // console.log(process.argv[2]) + if ( theOperator === "minus"){ + // With the .reduce method I used to take two values from the prevVal and currentVal and manipulate my array to the last value! + return sum = numbers.reduce((preiousVal, currentVal) => Number(preiousVal) - Number (currentVal)) +}} // Don't change anything below this line. module.exports = calculator;