postfix-calculator
v0.0.2
Published
Calculate a postfix (Reverse Polish Notation) expression.
Downloads
62
Maintainers
Readme
postfix-calculator
Calculate a postfix (Reverse Polish Notation) expression.
Demo
https://lab.miguelmota.com/postfix-calculator
Install
npm install postfix-calculator
Usage
const postfixCalculator = require('postfix-calculator');
console.log(postfixCalculator('1 2 +')); // 3
console.log(postfixCalculator('3 4 5 + *')); // 27
console.log(postfixCalculator('3 4 * 2 5 + / 3 4 + *')); // 12
console.log(postfixCalculator('57.5 -34.1 - 6 3.2 / * 4.3 +')); // 176.05
console.log(postfixCalculator('a & 5')); // null (invalid expressions return null)
Use the infix-to-postfix module for converting infix to postfix expressions.
Test
npm test
Credit
License
MIT