Created
August 2, 2020 09:35
-
-
Save AmyrAhmady/a2f254eb138480b14fc7cb5f675305e0 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
let input = "aabbccdaaaabb"; | |
let output = []; | |
for (let i = 0; i < input.length; i++) { | |
let current = input[i]; | |
let charStream = current.toString(); | |
let offset = 0; | |
if (input[i - 1] != input[i] && input[i + 1] != input[i]) { | |
output.push(charStream); | |
continue; | |
} | |
if (input[i - 1] == input[i]) continue; | |
for (let j = i + 1; j < input.length; j++) { | |
if (input[j] == current) { | |
offset++; | |
charStream += input[j].toString(); | |
} else { | |
i += offset; | |
break; | |
}; | |
} | |
output.push(charStream); | |
} | |
console.log(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment