1.0.4 • Published 3 years ago

@enigmaoffline/node-exp-solver v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Node Expression Solver

Mathematical expression solver / Reverse Polish Notation calculator for NodeJS

Features

  • Solve infix-notated mathematical expressions
  • Solve RPN expressions
  • Converts infix-notated expressions to RPN
  • Tokenize infix-notated expressions
    • From string to array
    • Able to handle negative numbers
    • Spacing independent

Install

With NPM:

npm install --save @enigmaoffline/node-exp-solver

Usage

const Solver = require('@enigmaoffline/node-exp-solver');

// Tokenization
console.log(Solver.tokenize('-1+2*(3-4)/5+(-6+-7)'));
// => [ '-1', '+', '2', '*', '(', '3', '-', '4', ')', '/', '5', '+', '(', '-6', '+', '-7', ')' ]
console.log(Solver.tokenize('1*2^3+3'));
// => [ '1', '*', '2', '^', '3', '+', '3' ]


// Infix to RPN
console.log(Solver.toRPN(Solver.tokenize('1+2*3')));
// => [ '1', '2', '3', '*', '+' ]


// Basic Solve
console.log(Solver.solve(Solver.tokenize('1+2*3')));
// => 7

// Solve RPN
console.log(Solver.solveRPN(Solver.toRPN(Solver.tokenize('-2+3^2+1'))));
// => 8

Next Steps

  1. Ability to handle Min / Max functions
  2. Ability to handle trig functions
  3. Ability to handle log functions

LICENSE - MIT - Lo Chung Tin

1.0.2

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago