Created
June 4, 2020 08:34
-
-
Save nikgoy/b6ff3b66283f3657de62da687609e7ce 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
// remove duplicates | |
crunch("ddaaiillyy ddoouubbllee"); // "daily double" | |
crunch("4444abcabccba"); // "4abcabcba" | |
crunch("ggggggggggggggg"); // "g" | |
crunch("a"); // "a" | |
crunch(""); // "" | |
function crunch(string) { | |
let letters = string.split(""); | |
for (let i = 0; i < letters.length; i++) { | |
if (letters[i] === letters[i + 1]) { | |
letters.splice(i, 1); | |
} | |
} | |
console.log(letters.join('')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment