0.0.2 • Published 7 years ago

postfix-calculator v0.0.2

Weekly downloads
23
License
MIT
Repository
github
Last release
7 years ago

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