I am trying to find an effective method for detecting repeated characters within a string, even if they are not placed next to each other. I attempted converting the string into an array and then utilizing nested loops to compare each element of the array against one another, but unfortunately, this approach did not yield the desired results.
function hasRepeatedChars(str) {
let arr = [];
for (let i = 0; i < str.length; i++) {
arr.push(str[i]);
}
for (let j = 0; j < arr.length; j++) {
for (let k = j + 1; k < arr.length; k++) {
if (arr[j] != arr[k]) {
return true;
} else {
return false;
}
}
}
}
hasRepeatedChars("abadan");