← Back to challenges

Prefix Notation Evaluation

JavaScriptHarddata_structuresarrayslanguage_fundamentals

Instructions

Create a function that takes a mathematical expression in prefix notation as a string and evaluates the expression.

Examples

prefix("+ 5 4") ➞ 9

prefix("* 12 2") ➞ 24

prefix("+ -10 10") ➞ 0

Notes

  • The mathematical expression is valid.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.