Skip to content

Instantly share code, notes, and snippets.

@timhuff
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhuff/ca1366cb9b954d1b48d9 to your computer and use it in GitHub Desktop.
Save timhuff/ca1366cb9b954d1b48d9 to your computer and use it in GitHub Desktop.
prefixString = "* + 2 3 4"
evaluatePrefix = (prefix)->
operator = prefix.shift()
leftValue = if isNaN parseFloat prefix[0] then evaluatePrefix prefix else prefix.shift()
rightValue = if isNaN parseFloat prefix[0] then evaluatePrefix prefix else prefix.shift()
eval leftValue+operator+rightValue
prefix = prefixString.split ' '
console.log evaluatePrefix prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment