Created
January 27, 2020 16:46
-
-
Save eveningkid/21bc2a0f96fc21e4ec78168962298ab3 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
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