Find the Longest Word in a String - getting right answers but still wrong

Find the Longest Word in a String - getting right answers but still wrong
0

#1

Hi fellow campers,

I seem to be getting right responses to the tests to this challenge but no green ticks - any ideas why?

Thanks

function findLongestWord(str) {

var split = str.split(" ");
var numList = [];
  for (var i = 0; i < split.length; i++ ) {
  array = [split[i].length];
  numList.push(array);
   
} 
numList.sort(function(a, b) {
  return a - b;
});
   return numList.pop().join();

 
}

findLongestWord("What if we try a super-long word such as otorhinolaryngology");

#2

Turns out you were returning a string. .join returns a string.


#3

Ah ok, that makes sense - thanks Kev

back to the drawing board :slight_smile:


#4

Hello, I have moved your post to the right category as it is not a wiki entry.