fix: preserve stack until operation completes
This commit is contained in:
@@ -369,9 +369,13 @@ class RpnCalculator {
|
||||
throw new Error('Stack underflow');
|
||||
}
|
||||
|
||||
const operands = argCount > 0 ? this.stack.splice(0, argCount).reverse() : [];
|
||||
const operands = argCount > 0 ? this.stack.slice(0, argCount).reverse() : [];
|
||||
const result = operation.execute(this, ...operands, ...args);
|
||||
|
||||
if (argCount > 0) {
|
||||
this.stack.splice(0, argCount);
|
||||
}
|
||||
|
||||
if (Array.isArray(result)) {
|
||||
for (let i = result.length - 1; i >= 0; i -= 1) {
|
||||
this.push(result[i]);
|
||||
|
||||
Reference in New Issue
Block a user