From bf2841081294727d040e72de5b9caf8e1bef6661 Mon Sep 17 00:00:00 2001 From: d98762625 Date: Tue, 15 May 2018 10:24:35 +0100 Subject: [PATCH] port multiply operation --- .../baseClasses => lib}/Arithmetic.mjs | 2 +- src/core/operations/Multiply.mjs | 48 +++++++++++++++++++ src/core/operations/Subtract.mjs | 2 +- src/core/operations/Sum.mjs | 2 +- 4 files changed, 51 insertions(+), 3 deletions(-) rename src/core/{operations/baseClasses => lib}/Arithmetic.mjs (99%) create mode 100644 src/core/operations/Multiply.mjs diff --git a/src/core/operations/baseClasses/Arithmetic.mjs b/src/core/lib/Arithmetic.mjs similarity index 99% rename from src/core/operations/baseClasses/Arithmetic.mjs rename to src/core/lib/Arithmetic.mjs index 37905362..7171c184 100644 --- a/src/core/operations/baseClasses/Arithmetic.mjs +++ b/src/core/lib/Arithmetic.mjs @@ -4,7 +4,7 @@ * @license Apache-2.0 */ -import Utils from "../../Utils"; +import Utils from "../Utils"; import BigNumber from "bignumber.js"; /** diff --git a/src/core/operations/Multiply.mjs b/src/core/operations/Multiply.mjs new file mode 100644 index 00000000..701beb43 --- /dev/null +++ b/src/core/operations/Multiply.mjs @@ -0,0 +1,48 @@ +/** + * @author d98762625 [d98762625@gmail.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import Arithmetic from "../lib/Arithmetic"; +import BigNumber from "bignumber.js"; + +/** + * Multiply operation + */ +class Multiply extends Operation { + + /** + * Multiply constructor + */ + constructor() { + super(); + + this.name = "Multiply"; + this.module = "Default"; + this.description = "Multiplies a list of numbers. If an item in the string is not a number it is excluded from the list.

e.g. 0x0a 8 .5 becomes 40"; + this.inputType = "string"; + this.outputType = "BigNumber"; + this.args = [ + { + "name": "Delimiter", + "type": "option", + "value": Arithmetic.DELIM_OPTIONS, + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {BigNumber} + */ + run(input, args) { + const val = Arithmetic._multi(Arithmetic._createNumArray(input, args[0])); + return val instanceof BigNumber ? val : new BigNumber(NaN); + } + +} + +export default Multiply; diff --git a/src/core/operations/Subtract.mjs b/src/core/operations/Subtract.mjs index 16d07e67..f0b24ee5 100644 --- a/src/core/operations/Subtract.mjs +++ b/src/core/operations/Subtract.mjs @@ -5,7 +5,7 @@ */ import Operation from "../Operation"; -import Arithmetic from "./baseClasses/Arithmetic"; +import Arithmetic from "../lib/Arithmetic"; import BigNumber from "bignumber.js"; /** diff --git a/src/core/operations/Sum.mjs b/src/core/operations/Sum.mjs index 8b2d2d9e..a79a8d7f 100644 --- a/src/core/operations/Sum.mjs +++ b/src/core/operations/Sum.mjs @@ -5,7 +5,7 @@ */ import Operation from "../Operation"; -import Arithmetic from "./baseClasses/Arithmetic"; +import Arithmetic from "../lib/Arithmetic"; import BigNumber from "bignumber.js"; /**