Why join and then split again, eh? - Refactor /add actually using the array provided as the array for the internal `parseNumericSeries` inside `performOperation`

0d38e634714ccb254799b390293066e54912bc37

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +5 -6Showing whitespace changes
public/scripts/variables.js+5 -6
@@ -669,8 +669,8 @@ function deleteGlobalVariable(name) {
669}669}
670670
671/**671/**
672 * Parses a series of numeric values from a string.672 * Parses a series of numeric values from a string or a string array.
673 * @param {string} value A space-separated list of numeric values or variable names673 * @param {string|string[]} value A space-separated list of numeric values or variable names
674 * @param {SlashCommandScope} scope Scope674 * @param {SlashCommandScope} scope Scope
675 * @returns {number[]} An array of numeric values675 * @returns {number[]} An array of numeric values
676 */676 */
@@ -679,9 +679,8 @@ function parseNumericSeries(value, scope = null) {
679 return [value];679 return [value];
680 }680 }
681681
682 const array = value682 const values = Array.isArray(value) ? value : value.split(' ');
683 .split(' ')683 const array = values.map(i => i.trim())
684 .map(i => i.trim())
685 .filter(i => i !== '')684 .filter(i => i !== '')
686 .map(i => isNaN(Number(i)) ? Number(resolveVariable(i, scope)) : Number(i))685 .map(i => isNaN(Number(i)) ? Number(resolveVariable(i, scope)) : Number(i))
687 .filter(i => !isNaN(i));686 .filter(i => !isNaN(i));
@@ -1595,7 +1594,7 @@ export function registerVariableCommands() {
1595 }));1594 }));
1596 SlashCommandParser.addCommandObject(SlashCommand.fromProps({1595 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
1597 name: 'add',1596 name: 'add',
1598 callback: (args, /**@type {string[]}*/value) => addValuesCallback(args, value.join(' ')),1597 callback: (args, value) => addValuesCallback(args, value),
1599 returns: 'sum of the provided values',1598 returns: 'sum of the provided values',
1600 unnamedArgumentList: [1599 unnamedArgumentList: [
1601 SlashCommandArgument.fromProps({1600 SlashCommandArgument.fromProps({