Infix Calculator

cehsu
17.9K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

The goal today is to write a function that evaluates a string that contains an arithmetic expression. We will do this by writing an calc function that calculates the expression using a stack.

For example:

  • calc("1 + 2 * (20 / 5 )") -> 9
  • calc("1 + 2 - 3") -> 0
  • calc("1 + 3 + ( ( 4 / 2 ) * ( 8 * 4 ) )") -> 68

See https://medium.freecodecamp.com/zipline-build-a-smart-javascript-calculator-65e21a8b0b0c for additional guidance.

Write the calc function
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content