writing code for the following algorithmic problem and no idea why it's not working. Following a debugger, I found that the elem variable never iterates beyond 's'. I'm concerned that this could be because of my understanding of how to break out of a parent for loop. I read this question: Best way to break from nested loops in Javascript? but I'm not sure if perhaps I'm doing something wrong.
function firstNonRepeatingLetter(s) {
//input string
//return first character that doesn't repeat anywhere else.
//parent for loop points to the char we are analyzing
//child for loop iterates over the remainder of the string
//if child for loop doesnt find a repeat, return the char, else break out of the child for loop and cont
if (s.length == 1) { return s;}
parent_loop:
for (var i = 0; i < s.length - 1; i++){ //parent loop
var elem = s[i];
child_loop:
for (var j = i + 1; j < s.length; j++){
if (elem == s[j]){
break child_loop;
}
}
return s[i];
}
return "";
}
console.log(firstNonRepeatingLetter('stress')); // should output t, getting s.