Skip to content

Instantly share code, notes, and snippets.

@blacksheep557
Last active June 2, 2020 08:23
Show Gist options
  • Select an option

  • Save blacksheep557/95b6996d7361a5a4fe7690f34d8675d0 to your computer and use it in GitHub Desktop.

Select an option

Save blacksheep557/95b6996d7361a5a4fe7690f34d8675d0 to your computer and use it in GitHub Desktop.
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;
}
@McLarenCollege
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment