Package detail

postfix-calculator

miguelmota42MIT0.0.2

Calculate a postfix (Reverse Polish Notation) expression.

postfix, reverse polish notation, rpn, notation

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

changelog

Change Log

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.