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