Created
May 19, 2022 15:01
-
-
Save thedom85/d10c08a3fe78ce32c4197f2bc450b2cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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