* Fix logic for empty or invalid values

This commit is contained in:
Dermott, Scott J 2021-11-25 20:27:12 +00:00
parent 3239d5599f
commit 7f260ec86b

View file

@ -32,13 +32,11 @@ class BasicArithmetic extends Operation {
*/
run(input, args) {
if (parseInt(input, 10).toString().length === input.length) {
const val = parseInt(input, 10);
return val;
return parseInt(input, 10);
} else if (input.match(/[+-]?([0-9.]+)/g)) {
return (input.replace(/\s/g, "").match(/[+-]?([0-9.]+)/g) || [])
.reduce(function (sum, value) {
const val = parseFloat(sum) + parseFloat(value);
return val;
return parseFloat(sum) + parseFloat(value);
});
} else {
return NaN;