Created
October 13, 2019 13:18
-
-
Save halfzebra/756f48ae32ad07e05af27329a5e9a009 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
console.clear() | |
function isBalanced(input) { | |
let stack = [] | |
const length = input.length | |
for (let i = 0; i < length; i++) { | |
if (input[i] === '(') { | |
stack.push('(') | |
} else { | |
stack.pop(); | |
} | |
} | |
return stack.length === 0 | |
} | |
console.log( | |
isBalanced('(())(())())') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment