Created
August 18, 2017 04:06
-
-
Save thebkr7/bd3f427d27fd3d0f85f943053e205423 to your computer and use it in GitHub Desktop.
Benji Richards
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
//NUMBER TWO: | |
//inputs: start and end nums | |
//outputs: array of numbers between start and end | |
function range(start, end) { | |
var rangeAnswer = []; | |
if(start < end && end ){ | |
for(var x = start; x < end; x++){ | |
rangeAnswer.push(x); | |
} | |
} | |
return(rangeAnswer); | |
} | |
/* | |
whole numbers: start, end | |
returns every number between start and end as an array | |
for(var x = start; x <= end; x++) | |
*/ | |
//NUMBER 4 | |
//inputs = array of people | |
//outputs = object containing the longest fullname | |
function longestName(people){ | |
var fullNameLength = 0; | |
var fullName = ''; | |
var longestFullName = ''; | |
//forloop to iterate over every index | |
for(var x = 0; x < people.length; x++) { | |
var objFullName = ''; | |
if(people[x].name.middle === undefined) { | |
objFullName = people[x].name.first + people[x].name.last; | |
} | |
else if(people[x].name.middle !== undefined) { | |
objFullName = people[x].name.first + people[x].name.middle + people[x].name.last; | |
} | |
if(fullNameLength < objFullName.length) { | |
fullNameLength = objFullName.length; | |
longestFullName = people[x]; | |
} | |
} | |
return longestFullName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment