Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Created June 3, 2014 21:00
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 ivanoats/86bf7e2acc9c2e77a1b4 to your computer and use it in GitHub Desktop.
Save ivanoats/86bf7e2acc9c2e77a1b4 to your computer and use it in GitHub Desktop.
'use strict';
var parenFinder = function (){
var parens = [];
var expression = process.argv[2];
var isOK = true;
for(var i = 0; i < expression.length; i++){
if (expression[i] === '('){
parens.push(i);
}
if (expression[i] === ')'){
if (parens.pop() === undefined){
console.log('Found unmatched ")" at index ' + i);
isOK = false;
}
}
}
while (parens.length > 0){
console.log('Found unmatched "(" at index ' + parens.pop());
isOK = false;
}
if (isOK){
console.log('No unmatched parentheses');
}
};
parenFinder();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment