Created
February 16, 2016 18:09
-
-
Save tjboudreaux/8f64a743778f60266a03 to your computer and use it in GitHub Desktop.
Stack Overflow Help
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
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