Created
January 6, 2021 18:37
-
-
Save gcjbr/ed46bf9da31558a0adf4ce8313ba0976 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
function SearchingChallenge(str: string): string | number { | |
const openers = ['(', '[']; | |
const closers = [')', ']']; | |
const collection = []; | |
let counter: number = 0; | |
let isValid = true; | |
[...str].forEach((char)=> { | |
if(openers.includes(char)) { | |
collection.push(char); | |
counter++; | |
} | |
if(closers.includes(char)) { | |
counter--; | |
} | |
if(counter < 0) { | |
isValid = false; | |
} | |
}) | |
return isValid ? `1 ${collection.length}` : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment