Created
March 27, 2015 22:02
-
-
Save troyleach/5aa193515b9425faeef8 to your computer and use it in GitHub Desktop.
Find the longest word in a phase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function findLongestWord() that takes an array of words and returns the length of the longest one. | |
// woops, didn't read it.... I took a phase turned it into a array... | |
var longestWord = ""; | |
function findLongestWord(phase) { | |
var sentence = phase.split(/\s/); | |
for ( var i = 0; i < sentence.length; i++ ) { | |
if (sentence[i].length > longestWord.length) { | |
longestWord = longestWord.replace(longestWord, sentence[i]); | |
} | |
} | |
return longestWord; | |
} | |
console.log(findLongestWord("find the longest word in this phase")); | |
var biggestWord = 'longest' | |
console.log(biggestWord === longestWord) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment