Code Monkey home page Code Monkey logo

testcalc's Introduction

The RPN CLI Calculator

Node.js Jest ESLint Replit


What is RPN? (Reverse Polish Notation)

In reverse Polish notation, the operators follow their operands. For example, to add 3 and 4 together, the expression is 3 4 + rather than 3 + 4. The expression 3 − 4 + 5 in conventional notation is 3 4 − 5 + in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it.

The concept of a stack, a last-in/first-out construct, is integral to the left-to-right evaluation of RPN. In the example 3 4 -, first the 3 is put onto the stack, then the 4; the 4 is now on top and the 3 below it. The subtraction operator removes the top two items from the stack, performs 3 - 4, and puts the result of -1 onto the stack.

The common terminology is that added items are pushed on the stack and removed items are popped.

The advantage of reverse Polish notation is that it removes the need for order of operations and parentheses that are required by infix notation and can be evaluated linearly, left-to-right. For example, the infix expression (3 × 4) + (5 × 6) becomes 3 4 × 5 6 × + in reverse Polish notation.

(Source: "Reverse Polish notation." Wikipedia)

High Level Description

This application is a command-line interface calculator that utilizes the concept of Reverse Polish Notation (RPN) to calculate mathematical expressions. The application is built with Node.js, tested with Jest, and follows ESLint rules for code quality.

Technical Choices and Trade-offs

The application is designed to be a CLI tool, as RPN inputs are naturally linear and work well with a command-line interface. Node.js was used due to its excellent support for command-line applications and I/O operations. Jest was used for testing due to its comprehensive feature set and simplicity. ESLint was used to ensure a consistent code style and catch potential errors early. While the testing for this calculator is sufficient for basic operation, not all of the features are fully tested for error handling and precise cases.

Getting Started

  1. Run 'npm install' to install necessary dependencies.
  2. Run 'npm start' or 'node cliInterface.js' in terminal to begin.
  3. Enter numbers and/or valid operations (+, -, *, /) on a single line with spaces between each input, or on separate lines without spaces.

Features

  1. Comprehensive testing suite using Jest. Run 'npm test' to execute.
  2. Stack tracking. Enter 'stack' during operation to see your current number stack.
  3. Stack manipulation. Enter 'clear' to remove all inputs. Enter 'back' to remove the most recent input.
  4. Calculation History. Enter 'history' to view all performed calculations for the current session.
  5. Error handling. Erroneous inputs are handled as to not interrupt user flow.

Developed By Github LinkedIn
PJ Bannon Github LinkedIn

testcalc's People

Contributors

yomkool avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.