Skip to content

Instantly share code, notes, and snippets.

@eveningkid
Created January 27, 2020 16:46
Show Gist options
  • Save eveningkid/21bc2a0f96fc21e4ec78168962298ab3 to your computer and use it in GitHub Desktop.
Save eveningkid/21bc2a0f96fc21e4ec78168962298ab3 to your computer and use it in GitHub Desktop.
module.exports = {
algo(input) {
const groups = [];
let currentGroup = '';
for (const letter of input.split('')) {
if (letter !== currentGroup.charAt(currentGroup.length - 1)) {
groups.push(currentGroup);
currentGroup = '';
}
currentGroup += letter;
}
groups.push(currentGroup);
groups.sort((groupA, groupB) => {
if (groupB.length < groupA.length) {
return -1;
} else if (groupB.length > groupA.length) {
return 1;
} else {
return 0;
}
});
return groups[0];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment