mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
* Fix logic for empty or invalid values
This commit is contained in:
parent
3239d5599f
commit
7f260ec86b
1 changed files with 2 additions and 4 deletions
|
@ -32,13 +32,11 @@ class BasicArithmetic extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
if (parseInt(input, 10).toString().length === input.length) {
|
if (parseInt(input, 10).toString().length === input.length) {
|
||||||
const val = parseInt(input, 10);
|
return parseInt(input, 10);
|
||||||
return val;
|
|
||||||
} else if (input.match(/[+-]?([0-9.]+)/g)) {
|
} else if (input.match(/[+-]?([0-9.]+)/g)) {
|
||||||
return (input.replace(/\s/g, "").match(/[+-]?([0-9.]+)/g) || [])
|
return (input.replace(/\s/g, "").match(/[+-]?([0-9.]+)/g) || [])
|
||||||
.reduce(function (sum, value) {
|
.reduce(function (sum, value) {
|
||||||
const val = parseFloat(sum) + parseFloat(value);
|
return parseFloat(sum) + parseFloat(value);
|
||||||
return val;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return NaN;
|
return NaN;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue