From cd86c705f3706aa605ac472005807578e3f04f86 Mon Sep 17 00:00:00 2001 From: cryosx Date: Mon, 19 Mar 2018 21:33:47 -1000 Subject: [PATCH 1/3] npm i --- package-lock.json | 162 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ff97aff --- /dev/null +++ b/package-lock.json @@ -0,0 +1,162 @@ +{ + "name": "js-calculator", + "version": "0.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "assertion-error": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.0.tgz", + "integrity": "sha1-x/hUOP3UZrx8oWq5DIFRN5el0js=" + }, + "chai": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-2.3.0.tgz", + "integrity": "sha1-ii9qNHSNqAEJD9cyh7Kqc5pOkJo=", + "requires": { + "assertion-error": "1.0.0", + "deep-eql": "0.1.3" + } + }, + "commander": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", + "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=" + }, + "debug": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "requires": { + "ms": "0.7.1" + } + }, + "deep-eql": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", + "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "requires": { + "type-detect": "0.1.1" + } + }, + "diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=" + }, + "escape-string-regexp": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", + "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=" + }, + "glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", + "requires": { + "inherits": "2.0.3", + "minimatch": "0.3.0" + } + }, + "growl": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", + "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "jade": { + "version": "0.26.3", + "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=" + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=" + } + } + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=" + }, + "minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.5.3.tgz", + "integrity": "sha1-FhvlvetJZ3HrmzV0UFC2IrWu/Fg=", + "requires": { + "commander": "2.3.0", + "debug": "2.2.0", + "diff": "1.4.0", + "escape-string-regexp": "1.0.2", + "glob": "3.2.11", + "growl": "1.9.2", + "jade": "0.26.3", + "mkdirp": "0.5.1", + "supports-color": "1.2.0", + "to-iso-string": "0.0.2" + } + }, + "ms": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=" + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=" + }, + "supports-color": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz", + "integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=" + }, + "to-iso-string": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/to-iso-string/-/to-iso-string-0.0.2.tgz", + "integrity": "sha1-TcGeZk38y+Jb2NtQiwDG2hWCVdE=" + }, + "type-detect": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", + "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=" + } + } +} From 8657e4eb074a6f23b1cef1cc1e1d54728f97802d Mon Sep 17 00:00:00 2001 From: cryosx Date: Mon, 19 Mar 2018 23:28:52 -1000 Subject: [PATCH 2/3] finished --- calculator.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/calculator.js b/calculator.js index 3e5744c..73f784d 100644 --- a/calculator.js +++ b/calculator.js @@ -6,6 +6,9 @@ * @return {object} `calculator` object that can be used */ +function calculatorModule(memory, total) { + let _total = 0; + let _memory = 0; /** * sets the `total` to the number passed in @@ -13,53 +16,116 @@ * @return { Number } current total */ + function load(x) { + if ((typeof x) === 'number') { + _total = x; + return _total; + } else { + throw new Error; + } + + } /** * Return the value of `total` * @return { Number } */ + function getTotal() { + return _total; + } /** * Sums the value passed in with `total` * @param { Number } x */ - + function add(x) { + if ((typeof x) === 'number') { + _total += x; + } else { + throw new Error; + } + } /** * Subtracts the value passed in from `total` * @param { Number } x */ + function subtract(x) { + if ((typeof x) === 'number') { + _total -= x; + } else { + throw new Error; + } + } /** * Multiplies the value by `total` * @param { Number } x */ - + function multiply(x) { + if ((typeof x) === 'number') { + _total *= x; + } else { + throw new Error; + } + } /** * Divides the value passing in by `total` * @param { Number } x */ + function divide(x) { + if ((typeof x) === 'number') { + _total /= x; + } else { + throw new Error; + } + } /** * Return the value stored at `memory` * @return { Number } */ + function recallMemory() { + return _memory; + } /** * Stores the value of `total` to `memory` */ + function saveMemory() { + _memory = _total; + } /** * Clear the value stored at `memory` */ + function clearMemory() { + _memory = 0; + } + /** * Validation */ + + + return { + load: load, + getTotal: getTotal, + add: add, + subtract: subtract, + multiply: multiply, + divide: divide, + recallMemory: recallMemory, + saveMemory: saveMemory, + clearMemory: clearMemory, + } + +} \ No newline at end of file From c671fbfb2377e9760d217e6cf52f3c409b43bb8a Mon Sep 17 00:00:00 2001 From: cryosx Date: Mon, 2 Apr 2018 16:12:48 -1000 Subject: [PATCH 3/3] fixed validation --- calculator.js | 68 +++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/calculator.js b/calculator.js index 73f784d..dbe9a0a 100644 --- a/calculator.js +++ b/calculator.js @@ -9,6 +9,18 @@ function calculatorModule(memory, total) { let _total = 0; let _memory = 0; + + return { + load: load, + getTotal: getTotal, + add: add, + subtract: subtract, + multiply: multiply, + divide: divide, + recallMemory: recallMemory, + saveMemory: saveMemory, + clearMemory: clearMemory, + } /** * sets the `total` to the number passed in @@ -17,13 +29,10 @@ function calculatorModule(memory, total) { */ function load(x) { - if ((typeof x) === 'number') { - _total = x; - return _total; - } else { - throw new Error; - } - + + validate(x); + _total = x; + return _total; } /** @@ -41,11 +50,8 @@ function calculatorModule(memory, total) { */ function add(x) { - if ((typeof x) === 'number') { - _total += x; - } else { - throw new Error; - } + validate(x); + _total += x; } /** * Subtracts the value passed in from `total` @@ -53,11 +59,8 @@ function calculatorModule(memory, total) { */ function subtract(x) { - if ((typeof x) === 'number') { - _total -= x; - } else { - throw new Error; - } + validate(x); + _total -= x; } /** @@ -65,11 +68,8 @@ function calculatorModule(memory, total) { * @param { Number } x */ function multiply(x) { - if ((typeof x) === 'number') { - _total *= x; - } else { - throw new Error; - } + validate(x); + _total *= x; } /** @@ -78,11 +78,8 @@ function calculatorModule(memory, total) { */ function divide(x) { - if ((typeof x) === 'number') { - _total /= x; - } else { - throw new Error; - } + validate(x); + _total /= x; } /** @@ -114,18 +111,9 @@ function calculatorModule(memory, total) { * Validation */ - - - return { - load: load, - getTotal: getTotal, - add: add, - subtract: subtract, - multiply: multiply, - divide: divide, - recallMemory: recallMemory, - saveMemory: saveMemory, - clearMemory: clearMemory, + function validate(x) { + if (typeof x !== 'number') { + throw new Error(); + } } - } \ No newline at end of file