Skip to content

Instantly share code, notes, and snippets.

@railsstudent
Created November 13, 2016 16:19
Show Gist options
  • Save railsstudent/3da0e34efd1389c6ed17946dd1357159 to your computer and use it in GitHub Desktop.
Save railsstudent/3da0e34efd1389c6ed17946dd1357159 to your computer and use it in GitHub Desktop.
Valid Braces kata published in codewars
validBraces = (braces) ->
bracesMap = {
']': '[',
')': '(',
'}': '{'
}
stack = [];
for i in [0...braces.length]
if braces[i] in ['(', '{', '['] then stack.push braces[i]
if braces[i] in [')','}', ']']
openBrace = bracesMap[braces[i]]
if stack[stack.length - 1] isnt openBrace then return false
else stack.pop()
return stack.length is 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment