separated all functions and updated comments/descriptions

This commit is contained in:
bwhitn 2017-12-21 05:58:31 -08:00
parent 0fea84ed7a
commit fc7d2c2f52
4 changed files with 155 additions and 42 deletions

View file

@ -128,7 +128,7 @@ const Categories = [
"Rotate right", "Rotate right",
"ROT13", "ROT13",
"Sum", "Sum",
"Sub", "Subtract",
"Multiply", "Multiply",
"Divide", "Divide",
"Mean", "Mean",
@ -166,7 +166,6 @@ const Categories = [
{ {
name: "Utils", name: "Utils",
ops: [ ops: [
"Arithmetic",
"Diff", "Diff",
"Remove whitespace", "Remove whitespace",
"Remove null bytes", "Remove null bytes",

View file

@ -658,9 +658,9 @@ const OperationConfig = {
} }
] ]
}, },
"Arithmetic": { "Sum": {
module: "Default", 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.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>18.5</code>",
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",
args: [ args: [
@ -668,11 +668,84 @@ const OperationConfig = {
name: "Delimiter", name: "Delimiter",
type: "option", type: "option",
value: Arithmetic.DELIM_OPTIONS 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.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>1.5</code>",
inputType: "string",
outputType: "string",
args: [
{ {
name: "Operation", name: "Delimiter",
type: "option", 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.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>40</code>",
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.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>2.5</code>",
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.<br><br>e.g. <code>0x0a 8 .5 .5</code> becomes <code>4.75</code>",
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.<br><br>e.g. <code>0x0a 8 1 .5</code> becomes <code>4.5</code>",
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.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>4.089281382128433</code>",
inputType: "string",
outputType: "string",
args: [
{
name: "Delimiter",
type: "option",
value: Arithmetic.DELIM_OPTIONS
} }
] ]
}, },

View file

@ -157,7 +157,13 @@ OpModules.Default = {
"Return": FlowControl.runReturn, "Return": FlowControl.runReturn,
"Comment": FlowControl.runComment, "Comment": FlowControl.runComment,
"PHP Deserialize": PHP.runDeserialize, "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,
/* /*

View file

@ -17,72 +17,107 @@ const Arithmetic = {
*/ */
DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"], 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 {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {number} * @returns {string}
*/ */
computeSum: function(input, args) { runSum: function(input, args) {
const val = Arithmetic._sum(Arithmetic._createNumArray(input, args[0])); 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])); 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])); 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])); 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])); 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])); 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])); 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) { _createNumArray: function(input, delim) {
const delim = Utils.charRep[delim || "Space"]; delim = Utils.charRep[delim || "Space"];
let splitNumbers = input.split(delim), let splitNumbers = input.split(delim),
numbers = [], numbers = [],
num; 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 * @private
* @param {number[]} data * @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 * @private
* @param {number[]} data * @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 * @private
* @param {number[]} data * @param {number[]} data