Skip to content

Instantly share code, notes, and snippets.

@halfzebra
Created October 13, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halfzebra/756f48ae32ad07e05af27329a5e9a009 to your computer and use it in GitHub Desktop.
Save halfzebra/756f48ae32ad07e05af27329a5e9a009 to your computer and use it in GitHub Desktop.
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