mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 02:32:55 +02:00
Fixed bugs with refactored Company/job code. Added 'expr' Terminal command
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user