Fixed bugs with refactored Company/job code. Added 'expr' Terminal command

This commit is contained in:
danielyxie
2018-11-17 16:23:48 -08:00
parent 9b3ff6d2d3
commit b242ca2f42
13 changed files with 679 additions and 575 deletions
+18
View File
@@ -1090,6 +1090,24 @@ let Terminal = {
}
}
post("Error: " + fn + " does not exist");
break;
case "expr":
if (commandArray.length <= 1) {
post("Incorrect usage of expr command. Usage: expr [math expression]");
return;
}
const expr = commandArray.slice(1).join("");
// Sanitize the math expression
const sanitizedExpr = expr.replace(/s+/g, '').replace(/[^-()\d/*+.]/g, '');
let result;
try {
result = eval(sanitizedExpr);
} catch(e) {
post(`Could not evaluate expression: ${sanitizedExpr}`);
return;
}
post(result);
break;
case "free":
Terminal.executeFreeCommand(commandArray);