Instantly share code, notes, and snippets.

# FSou1/valid-braces.js

Last active September 24, 2020 23:14
Show Gist options
• Save FSou1/e6bb26e68de3b966c241cd7a2df66e7c 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
 // Valid Braces // https://www.codewars.com/kata/5277c8a221e209d3f6000b56 /* Solution 1 */ function validBraces(braces){ var queue = []; for(var brace of braces) { if(brace === '(' || brace === '{' || brace === '[') { queue.push(brace); } else { var last = queue.pop(); if(last === '(' && brace === ')') { continue; } else if (last === '[' && brace === ']') { continue; } else if (last === '{' && brace === '}') { continue; } else { return false; } } } return queue.length === 0; } /* Solution 2 */ function validBraces(braces){ var matches = { '(':')', '{':'}', '[':']' }; var queue = []; for(var brace of braces) { if (matches[brace]) { queue.push(brace); } else { if (brace !== matches[queue.pop()]) { return false; } } } return queue.length === 0; } /* Solution 3 */ function validBraces(braces){ while(braces.indexOf("{}") != -1 || braces.indexOf("()") != -1 || braces.indexOf("[]") != -1){ braces = braces.replace("{}", "").replace("()", "").replace("[]", ""); } return braces.length == 0; }

### danielllumiquinga commented Sep 22, 2020

que tengo que hacer para conseguir robux