Created
January 11, 2019 21:51
-
-
Save tom-wagner/76293c6e548944711a08430f740c94e6 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
| const polymer = (string) => { | |
| const arr = string.split(''); | |
| const stack = []; | |
| for (let i = 0; i < arr.length; i++) { | |
| let lastStackVal = stack[stack.length - 1]; | |
| let currOppositeCase = arr[i] === arr[i].toUpperCase() ? arr[i].toLowerCase() : arr[i].toUpperCase(); | |
| if (lastStackVal === currOppositeCase) { | |
| stack.pop(); | |
| } else { | |
| stack.push(arr[i]); | |
| } | |
| } | |
| return stack.length; | |
| }; | |
| let str = 'dabAcCaCBAcCcaDA' | |
| polymer(str); // 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment