UNPKG

@enigmaoffline/node-exp-solver

Version:

Mathematical expression solver / Reverse Polish Notation calculator for NodeJS

35 lines (34 loc) 1.33 kB
declare class Solver { /** * Tokenize an infix-notated expression string * @param {string} exp - mathematical expression * @returns {Array<string>} - tokenized expression */ static tokenize: (exp: string) => Array<string>; /** * Converts an infix-notated expression to reverse polish notation * @param {Array<string>} exp - tokenized infix-notated expression * @returns {Array<string>} - converted RPN expression */ static toRPN: (exp: Array<string>) => Array<string>; /** * Evaluates an infix-notated expression * @param {Array<string>} exp - tokenzied infix-notated expression * @returns - evaluated value */ static solve: (exp: Array<string>) => number; /** * Evaluates a reverse polish notated expression * @param {Array<string>} rpn - tokenized rpn expression * @returns {number} - evaluated value */ static solveRPN: (rpn: Array<string>) => number; /** * Recursively solve an RPN expression * @param {Array<string>} rpn - original RPN expression * @param {Array<number>} stack - memory stack used for recursive computation * @returns {number} - evaluated value */ private static solveRec; } export = Solver;