Created
June 3, 2014 21:00
-
-
Save ivanoats/86bf7e2acc9c2e77a1b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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