You are viewing a single comment's thread. Return to all comments →
JavaScript port for fun:
function is_balanced(expression) { let s = []; expression = expression.split(''); for (let c = 0; c < expression.length; c++) { if (expression[c] === '{') { s.push('}'); } else if (expression[c] === '[') { s.push(']'); } else if (expression[c] === '(') { s.push(')'); } else { if ((s.length === 0) || expression[c] !== s[s.length-1]) { return false; } s.pop(); } }; return (s.length === 0); }
Seems like cookies are disabled on this browser, please enable them to open this website
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
JavaScript port for fun: