Skip to content

Instantly share code, notes, and snippets.

@erictleung
Created November 17, 2015 02:22
Show Gist options
  • Save erictleung/0b1f4f43e0f234300129 to your computer and use it in GitHub Desktop.
Save erictleung/0b1f4f43e0f234300129 to your computer and use it in GitHub Desktop.
Find longest word within a space separated sentence
function findLongestWord(str) {
var splitStr = str.split(" ");
var long = 0;
for (i = 0; i < splitStr.length; i++) {
if (splitStr[i].length > long) {
long = splitStr[i].length;
}
}
return long;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment