Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Forked from AndyCErnst/parenFinder.js
Created June 3, 2014 20:43
Show Gist options
  • Save ivanoats/e345e1966b01b7e33a37 to your computer and use it in GitHub Desktop.
Save ivanoats/e345e1966b01b7e33a37 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