Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function findLongestWord(str) {
  2. //Make string into array, with each word as an array value
  3. var strArray = str.split(" ");
  4. //Create variable to hold value of longest word
  5. var longestWord = 0;
  6. //Iterate through the array and find the length of each value to determine longest word
  7. for (var i = 0; i < strArray.length; i++) {
  8. if (strArray[i].length > longestWord) {
  9. longestWord = strArray[i].length;
  10. }
  11. }
  12. return longestWord;
  13. }
  14.  
  15. findLongestWord("The quick brown fox jumped over the lazy dog");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement