Skip to content

CharlesYiu/calculation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Calculation.ts

Evaluates calculations

syntax

The syntax is like regular javascript with the exponent ('**') be '^' instead

generateTape(calculation: string): Tape

Original text: '1+(2-1)'
Parsed text (Tape):

[
  1,
  "+",
  [
    2,
    "-",
    1
  ]
]

calculateTape(calculationTape: Tape): number

Tape (parsed text):

[
  1,
  "+",
  [
    2,
    "-",
    1
  ]
]

Result: 2

usage

You can use this by importing the script or running it with node (ts) like this:

$ ts-node calculation.ts '1+(2-1)'
[ 1, '+', [ 2, '-', 1 ] ]
2

About

Evaluates calculations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published