Code Etiquette

Challenge accepted!

// You are building an educational website and want to create a simple
// calculator for students to use. The calculator will only allow
// addition and subtraction of positive integers.
//
// We also want to allow parentheses in our input. Given an expression
// string using the "+", "-", "(", and ")" operators like "5+(16-2)",
// write a function to parse the string and evaluate the result.

// Sample input:
//     expression1 = "5+16-((9-6)-(4-2))"
//     expression2 = "22+(2-4)"
 
// Sample output:
//     evaluate(expression1) => 20
//     evaluate(expression2) => 20

Recently, I did a live ses­sion where I was chal­lenged to imple­ment some code in a short peri­od of time.  I got flus­tered, and I diverged from my usu­al­ly strict prin­ci­ples of code eti­quette and wrote some messy code that nev­er end­ed up work­ing by the end of the ses­sion.  I had an ele­gant solu­tion in mind, but I was wor­ried about time and end­ed up with this mess.

Continue read­ing…