Skip to content

Instantly share code, notes, and snippets.

@AndyCErnst
Last active August 29, 2015 14:02
Show Gist options
  • Save AndyCErnst/f009a2fb95cbd3871649 to your computer and use it in GitHub Desktop.
Save AndyCErnst/f009a2fb95cbd3871649 to your computer and use it in GitHub Desktop.
paren finder
'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