0.1.0 • Published 6 years ago

rpn.js v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

rpn.js

Reverse polish notation (RPN).

Converts any string equation (infix notation) to RPN. Calculates RPN notations.

Installation

npm install rpn.js
or
yarn add rpn.js

Usage

See tests directory for more examples.

infixToRPN

import { infixToRPN } from 'rpn.js';

const infix = '(2 + 2) * 2';
const rpn = infixToRPN(infix);

console.log(rpn);
// => [2, 2, 2, '+', '*']

calculateRPN

import { calculateRPN } from 'rpn.js';

const rpn = [2, 2, 2, '+', '*'];
const result = calculateRPN(rpn);

console.log(result);
// => 8