diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js
index 0ab32eb1..8fc8ac02 100755
--- a/src/core/config/Categories.js
+++ b/src/core/config/Categories.js
@@ -128,7 +128,7 @@ const Categories = [
"Rotate right",
"ROT13",
"Sum",
- "Sub",
+ "Subtract",
"Multiply",
"Divide",
"Mean",
@@ -166,7 +166,6 @@ const Categories = [
{
name: "Utils",
ops: [
- "Arithmetic",
"Diff",
"Remove whitespace",
"Remove null bytes",
diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js
index 9f41f2f8..93c82adf 100755
--- a/src/core/config/OperationConfig.js
+++ b/src/core/config/OperationConfig.js
@@ -658,9 +658,9 @@ const OperationConfig = {
}
]
},
- "Arithmetic": {
+ "Sum": {
module: "Default",
- description: "Conducts mathamatical operations on a list of numbers",
+ description: "Sums 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 18.5
",
inputType: "string",
outputType: "string",
args: [
@@ -668,11 +668,84 @@ const OperationConfig = {
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
- },
+ }
+ ]
+ },
+ "Subtract": {
+ module: "Default",
+ description: "Subtracts 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 1.5
",
+ inputType: "string",
+ outputType: "string",
+ args: [
{
- name: "Operation",
+ name: "Delimiter",
type: "option",
- value: Arithmetic.OPERATIONS
+ value: Arithmetic.DELIM_OPTIONS
+ }
+ ]
+ },
+ "Multiply": {
+ module: "Default",
+ 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
",
+ inputType: "string",
+ outputType: "string",
+ args: [
+ {
+ name: "Delimiter",
+ type: "option",
+ value: Arithmetic.DELIM_OPTIONS
+ }
+ ]
+ },
+ "Divide": {
+ module: "Default",
+ description: "Divides 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 2.5
",
+ inputType: "string",
+ outputType: "string",
+ args: [
+ {
+ name: "Delimiter",
+ type: "option",
+ value: Arithmetic.DELIM_OPTIONS
+ }
+ ]
+ },
+ "Mean": {
+ module: "Default",
+ description: "Computes the mean (average) of a number list. If an item in the string is not a number it is excluded from the list.
e.g. 0x0a 8 .5 .5
becomes 4.75
",
+ inputType: "string",
+ outputType: "string",
+ args: [
+ {
+ name: "Delimiter",
+ type: "option",
+ value: Arithmetic.DELIM_OPTIONS
+ }
+ ]
+ },
+ "Median": {
+ module: "Default",
+ description: "Computes the median of a number list. If an item in the string is not a number it is excluded from the list.
e.g. 0x0a 8 1 .5
becomes 4.5
",
+ inputType: "string",
+ outputType: "string",
+ args: [
+ {
+ name: "Delimiter",
+ type: "option",
+ value: Arithmetic.DELIM_OPTIONS
+ }
+ ]
+ },
+ "Standard Deviation": {
+ module: "Default",
+ description: "Computes the standard deviation of a number list. If an item in the string is not a number it is excluded from the list.
e.g. 0x0a 8 .5
becomes 4.089281382128433
",
+ inputType: "string",
+ outputType: "string",
+ args: [
+ {
+ name: "Delimiter",
+ type: "option",
+ value: Arithmetic.DELIM_OPTIONS
}
]
},
diff --git a/src/core/config/modules/Default.js b/src/core/config/modules/Default.js
index 6f672ce2..9a373e12 100644
--- a/src/core/config/modules/Default.js
+++ b/src/core/config/modules/Default.js
@@ -157,7 +157,13 @@ OpModules.Default = {
"Return": FlowControl.runReturn,
"Comment": FlowControl.runComment,
"PHP Deserialize": PHP.runDeserialize,
- "Arithmetic": Arithmetic.runOp,
+ "Sum": Arithmetic.runSum,
+ "Subtract": Arithmetic.runSub,
+ "Multiply": Arithmetic.runMulti,
+ "Divide": Arithmetic.runDiv,
+ "Mean": Arithmetic.runMean,
+ "Median": Arithmetic.runMedian,
+ "Standard Deviation": Arithmetic.runStdDev,
/*
diff --git a/src/core/operations/Arithmetic.js b/src/core/operations/Arithmetic.js
index 6472a7fc..9b07f8ad 100644
--- a/src/core/operations/Arithmetic.js
+++ b/src/core/operations/Arithmetic.js
@@ -17,72 +17,107 @@ const Arithmetic = {
*/
DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"],
- /**
- * @constant
- * @default
- */
- OPERATIONS: [
- "Sum",
- "Sub",
- "Multiply",
- "Divide",
- "Mean",
- "Median",
- "Standard Deviation"
- ],
-
/**
- *
+ * Splits a string based on a delimiter and calculates the sum of numbers.
*
* @param {string} input
* @param {Object[]} args
- * @returns {number}
+ * @returns {string}
*/
- computeSum: function(input, args) {
+ runSum: function(input, args) {
const val = Arithmetic._sum(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
- computeSub: function(input, args) {
+ /**
+ * Splits a string based on a delimiter and subtracts all the numbers.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runSub: function(input, args) {
let val = Arithmetic._sub(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
- computeMulti: function(input, args) {
+ /**
+ * Splits a string based on a delimiter and multiplies the numbers.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runMulti: function(input, args) {
let val = Arithmetic._multi(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
- computeDiv: function(input, args) {
+ /**
+ * Splits a string based on a delimiter and divides the numbers.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runDiv: function(input, args) {
let val = Arithmetic._div(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
- computeMean: function(input, args) {
+ /**
+ * Splits a string based on a delimiter and computes the mean (average).
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runMean: function(input, args) {
let val = Arithmetic._mean(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
- computeMedian: function(input, args) {
+ /**
+ * Splits a string based on a delimiter and finds the median.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runMedian: function(input, args) {
let val = Arithmetic._median(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
- computeStdDev: function(input, args) {
+ /**
+ * splits a string based on a delimiter and computes the standard deviation.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runStdDev: function(input, args) {
let val = Arithmetic._stdDev(Arithmetic._createNumArray(input, args[0]));
- return typeof(val) === 'number' ? val.toString() : "";
+ return typeof(val) === "number" ? val.toString() : "";
},
+ /**
+ * Converts a string array to a number array.
+ *
+ * @param {string[]} input
+ * @param {string} delim
+ * @returns {number[]}
+ */
_createNumArray: function(input, delim) {
- const delim = Utils.charRep[delim || "Space"];
+ delim = Utils.charRep[delim || "Space"];
let splitNumbers = input.split(delim),
numbers = [],
num;
@@ -153,7 +188,7 @@ const Arithmetic = {
},
/**
- * Finds the mean of a number array and returns the value.
+ * Computes mean of a number array and returns the value.
*
* @private
* @param {number[]} data
@@ -166,7 +201,7 @@ const Arithmetic = {
},
/**
- * Finds the median of a number array and returns the value.
+ * Computes median of a number array and returns the value.
*
* @private
* @param {number[]} data
@@ -187,7 +222,7 @@ const Arithmetic = {
},
/**
- * Finds the standard deviation of a number array and returns the value.
+ * Computes standard deviation of a number array and returns the value.
*
* @private
* @param {number[]} data