괄호가 유효한지 체크
function validBraces(braces){
var stack = [];
return braces.split('').map(b=> {
if ('({['.indexOf(b)>=0) {
stack.push(b);
return true;
} else {
var e = stack.pop();
return '({['.indexOf(e) == ')}]'.indexOf(b);
}
}).every(b=>b) && stack.length == 0;
}
function validBraces(braces){
while(braces.indexOf("{}") != -1 || braces.indexOf("()") != -1 || braces.indexOf("[]") != -1){
braces = braces.replace("{}", "").replace("()", "").replace("[]", "");
}
return braces.length == 0;
}
function validBraces(braces){
while(/\(\)|\[\]|\{\}/g.test(braces)){braces = braces.replace(/\(\)|\[\]|\{\}/g,"")}
return !braces.length;
}
You have publicly posted copyrighted content from Codewars.com. If any of these solutions are original works by you, you can leave them up but please remove all references to which kata they belong to or the fact that they are related to Codewars.