postfix-calculator

0.0.2 • Public • Published

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

Package Sidebar

Install

npm i postfix-calculator

Weekly Downloads

18

Version

0.0.2

License

MIT

Last publish

Collaborators

  • miguelmota