Skip to content

maheel/postfix-evaluator

Repository files navigation

Postfix Evaluator (Spreadsheet)

Approach

Read CSV file and get te data into a multi-dimensional array.
Each cell represents one postfix expression. Hence, evaluate each expression individually.
For each expression:
Hash expression and check if expression has been already evaluated (expressions with a cell reference will be stored once evaluated)if so return the value,
if not:
Split expression into tokens.
for each token in the postfix expression:
if token is an operator:
operand_2 ← pop from the stack
operand_1 ← pop from the stack
result ← evaluate token with operand_1 and operand_2
push result back onto the stack
else if token is an operand:
push token onto the stack
else if token is a cell reference:
if token has been calculated already:
get it from the cached object and push onto the stack
else:
get the corresponding array index of the cell reference
get the cell value (expression) from the multi-dimensional array
evaluate expression and push on to the stack
store evaluated value into calculated tokens
hash the expression and store along with the evaluated cell value to use in the future
result ← pop from the stack
Collect all evaluated values into multi-dimensional array and write to a csv file.

**Assumptions : Always CSV file will be uploaded. **

Folder structure
  • Node.js Version: 10.15
  • src - Source folder
  • test - Test folder
  • upload - Input Folder
  • download - Output folder
How To Run the Programs

Some file has been included inupload folder.

npm install
node src/index.js postfix --inputFile="inputFile.csv" --outputFile="outputFile.csv"
Run Lint
npm run lint
Run Tests
npm run test
Run Test Coverage

Current test coverage: 81.5%

npm run coverage

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published