Last active
June 2, 2020 08:23
-
-
Save blacksheep557/95b6996d7361a5a4fe7690f34d8675d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function withoutRegExp(string = '') { | |
| let queue = []; | |
| let currentString = ''; | |
| for (let i = 0; i < string.length; i++) { | |
| if (string.charAt(i) === '(') { | |
| queue.push(currentString); | |
| currentString = ''; | |
| } else if (string.charAt(i) === ')') { | |
| currentString = queue.pop() + currentString.split('').reverse().join(''); | |
| } else { | |
| currentString += string.charAt(i); | |
| } | |
| } | |
| console.log(currentString); | |
| return currentString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Correctness: 60/60
Code Quality: 30/40
For regex solution you don't need foundMatch variable, the while loop will run as long as there is a
)present in the string.