Skip to content

Instantly share code, notes, and snippets.

@thedom85
Created May 19, 2022 15:01
Show Gist options
  • Save thedom85/d10c08a3fe78ce32c4197f2bc450b2cc to your computer and use it in GitHub Desktop.
Save thedom85/d10c08a3fe78ce32c4197f2bc450b2cc to your computer and use it in GitHub Desktop.
// https://www.codewars.com/kata/52774a314c2333f0a7000688/train/javascript
function validParentheses(parens) {
var count =0;
for (var i = 0; i < parens.length; i++) {
if(parens.charAt(i) =="(") count++;
if(parens.charAt(i) ==")") count--;
if(count ==-1 ) return false;
}
if(count == 0 ) return true;
return false;
}
console.log(validParentheses("("),false);
console.log(validParentheses("(("),false);
console.log(validParentheses(")"),false);
console.log(validParentheses("()"),true);
console.log(validParentheses("())("),false);
console.log(validParentheses("())("),false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment