- 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.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
// Find the maximum | ||
function maxOfTwoNumbers (item1, item2) { | ||
if (item1>item2) { | ||
return item1; | ||
} | ||
else { | ||
return item2; | ||
} | ||
} | ||
// Finding Longest Word | ||
var words = [ | ||
'mystery', | ||
@@ -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 commentThe 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).
| ||
for (var i=0; i < box.length; i++) { | ||
if (box[i].length > longest.length) { | ||
var longest = box[i]; | ||
} else { | ||
} | ||
} | ||
return longest; | ||
} | ||
// Calculating a Sum | ||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||