I need some assistance with a method I am developing for an array function called RPNCalculator. Unfortunately, it is not functioning correctly at the moment.
An issue arises when performing subtraction operations within the calculator. For example, when subtracting 3 from 8, the result is returning 5 instead of -5. Similarly, when subtracting 3 from 4, it returns 1 instead of -1. This discrepancy can be observed in the num variable.
Your help in resolving this problem would be greatly appreciated.
RPN values: [2, 3 ,4]
RPNCalculator.prototype.minus = function() {
console.log("First item " + this[this.length - 2] + "\nLast Item " + this[this.length - 1]);
/* Logs:First item 3
Last Item 4 */
var num = this.pop(this[this.length - 2]) - this.pop(this[this.length - 1]);
console.log(num); // logs 1
this.push(num);
};