Reverse polish notation (RPN).
Converts any string equation (infix notation) to RPN. Calculates RPN notations.
npm install rpn.js
or
yarn add rpn.js
See tests directory for more examples.
import { infixToRPN } from 'rpn.js';
const infix = '(2 + 2) * 2';
const rpn = infixToRPN(infix);
console.log(rpn);
// => [2, 2, 2, '+', '*']
import { calculateRPN } from 'rpn.js';
const rpn = [2, 2, 2, '+', '*'];
const result = calculateRPN(rpn);
console.log(result);
// => 8