Why join and then split again, eh? - Refactor /add actually using the array provided as the array for the internal `parseNumericSeries` inside `performOperation`
| @@ -669,8 +669,8 @@ function deleteGlobalVariable(name) { | ||
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
| 672 | 672 | * Parses a series of numeric values from a string or a string array. |
| 673 | 673 | * @param {string|string[]} value A space-separated list of numeric values or variable names |
| 674 | 674 | * @param {SlashCommandScope} scope Scope |
| 675 | 675 | * @returns {number[]} An array of numeric values |
| 676 | 676 | */ |
| @@ -679,9 +679,8 @@ function parseNumericSeries(value, scope = null) { | ||
| 679 | 679 | return [value]; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - const array = value | |
| 682 | + const values = Array.isArray(value) ? value : value.split(' '); | |
| 683 | - .split(' ') | |
| 683 | + const array = values.map(i => i.trim()) | |
| 684 | - .map(i => i.trim()) | |
| 685 | 684 | .filter(i => i !== '') |
| 686 | 685 | .map(i => isNaN(Number(i)) ? Number(resolveVariable(i, scope)) : Number(i)) |
| 687 | 686 | .filter(i => !isNaN(i)); |
| @@ -1595,7 +1594,7 @@ export function registerVariableCommands() { | ||
| 1595 | 1594 | })); |
| 1596 | 1595 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 1597 | 1596 | name: 'add', |
| 1598 | 1597 | callback: (args, /**@type {string[]}*/value) => addValuesCallback(args, value.join(' ')), |
| 1599 | 1598 | returns: 'sum of the provided values', |
| 1600 | 1599 | unnamedArgumentList: [ |
| 1601 | 1600 | SlashCommandArgument.fromProps({ |