Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const crushOnce = (xs) => {
if (xs.length < 3) return xs;
let count = 0;
for (const x of xs) {
if (x !== xs[0]) break;
count++;
}
if (count >= 3) {
return crush(xs.slice(count));
}
return xs.slice(0, count) + crush(xs.slice(count));
};
const crush = (ss) => {
const crushed = crushOnce(ss);
if(crushed == ss) return ss;
return crushOnce(crushed);
}
crush('aabbccddeeedcbak'); // "k"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.