In the following code, why does every character appear to be equal to every other character?
Write a JavaScript function that takes a sentence as an argument and determines which word in that sentence has the greatest number of repeated letters (the repeated letters do not have to be consecutive).
If the sentence has multiple words with the same max of repeated letters, return them all in an Array.
var repeatedLettersInAString = function(){
var repeatedLetterCount = 0;
var wordsWithRepeatedLetters = {};
var userString = prompt("enter your string", "it will go here!").split(' ');
/* var i selects the array element, var x will be the
character to which var n will be compared. */
console.log(userString);
for(var i = 0; i < userString.length; i++){
console.log(userString[i] + " userString");
for (var x = 0; x < userString[i].length; x++){
for (var n = 0; n < userString[i].length; n++){
if (userString[i].charAt(x) === userString[i].charAt(n), x!==n){
repeatedLetterCount++;
wordsWithRepeatedLetters[i] = userString[i];
console.log(wordsWithRepeatedLetters);
}else{
console.log("There are no repeating characters");
}
}
}
}
console.log(repeatedLetterCount);
console.log(wordsWithRepeatedLetters);
};
repeatedLettersInAString();