This is my first time posting here and I'm only doing this because I have researched all over the place. There are questions out there that are coded similarly but they weren't looking for the right thing that would help me.
var sentence = "The Shattuck is the best"
var longest = function(str) {
var strArr = str.split(" ");
for (var i = 0; i < strArr.length; i++) {
for (var j = 0; j < strArr.length; j++) {
if (strArr[i].length > strArr[j].length) {
strArr.splice(j, 1);
} else {
j = 0
}
}
}
return strArr
};
longest(sentence);
//should return Shattuck but I get an infinite loop problem.