Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findLongestWord(str) {
- array = str.split(' ');
- var longest;
- var length = 0;
- for (i = 0; i < array.length; i++) {
- if (array[i].length > length) {
- length = array[i].length;
- longest = array[i];
- }
- }
- return longest.length;
- }
- findLongestWord("The quick brown fox jumped over the lazy dog");
Add Comment
Please, Sign In to add comment