separated all functions and updated comments/descriptions
This commit is contained in:
parent
0fea84ed7a
commit
fc7d2c2f52
@ -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",
|
||||
|
@ -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.<br><br>e.g. <code>0x0a 8 .5</code> becomes <code>18.5</code>",
|
||||
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.<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",
|
||||
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
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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,
|
||||
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user