Returning the length of largest word in a sentence : <p>I have written a function which receives a sentence and calculates the longest word in that sentence.</p>

<pre><code>function findLongestWord(str) {

  var charArray = str.split(" ");
  var wordArray = [];


  for(var i = 0; i &lt; charArray.length; i++ ) {
    wordArray.push(charArray[i].length);
    wordArray.sort();
    wordArray.reverse();

  }

  return wordArray[0];
}
</code></pre>

<p>My function works with inputs such as:</p>

<pre><code>findLongestWord("The quick brown fox jumped over the lazy dog");
</code></pre>

<p>But when i pass it: </p>

<pre><code>findLongestWord("What if we try a super-long word such as otorhinolaryngology")
</code></pre>

<p>The function returns:</p>

<pre><code>4
</code></pre>

<p>Rather than </p>

<pre><code>19
</code></pre>
