Skip to content

Instantly share code, notes, and snippets.

@tjboudreaux
Created February 16, 2016 18:09
Show Gist options
  • Save tjboudreaux/8f64a743778f60266a03 to your computer and use it in GitHub Desktop.
Save tjboudreaux/8f64a743778f60266a03 to your computer and use it in GitHub Desktop.
Stack Overflow Help
function wordsWithRepeatedChars(str) {
var list = [];
//split string into words based on spaces and count repeated characters
str.toLowerCase().split(" ").forEach(function(currentWord){
var lastLetter = "";
var alreadyAdded = false;
//split word into characters and add to the list only if a letter repeats
currentWord.split('').forEach(function(letter){
if (letter == lastLetter && !alreadyAdded) {
list.push(currentWord);
alreadyAdded = true;
}
lastLetter = letter;
});
});
return list;
}
console.log(wordsWithRepeatedChars("aaa bbb abcbc"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment