Back
Close

Infix Calculator

cehsu
17.4K views

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
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io