- Notifications
You must be signed in to change notification settings - Fork6.7k
BCN - Linda & Santiago#215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Good job, continue like that! 👍
@@ -11,6 +21,22 @@ var words = [ | |||
'crackpot' | |||
]; | |||
function findLongestWord (box){ | |||
var longest = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This function will fail returning undefined when the array is empty. You can solve this checking if the array is empty and returning undefined then. A better way is asign to your comparator (longest) the first array's element. If the array is empty, longest will be 'undefined' and the function will return 'undefined'. Using an internal element for comparision solve some tricky problems (e.g. finding a minimum).
function findLongestWord(box) { var longest = box[0]; for (var i = 1; i < box.length; i++) { if (box[i].length > longest.length) { longest = box[i]; } } return longest;}
@lindaluisa