When executing the $ instruction, if the stack only has two elements, then we can just reverse the stack and continue.
@@ -101,6 +101,7 @@ export class Stack {
*/
public swapTwo() {
if(this.stack.length < 2) { throw new WrongStackSizeError(2, this.stack.length); }
+ if (this.stack.length == 2) { this.stack.reverse(); return; }
const popped = this.stack.splice(this.stack.length - 2, 2);
this.stack.push(...popped.reverse());