Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created October 7, 2022 18:24
Show Gist options
  • Save IrhaAli/4014682a6a599e459b514fb72645d929 to your computer and use it in GitHub Desktop.
Save IrhaAli/4014682a6a599e459b514fb72645d929 to your computer and use it in GitHub Desktop.
Returns the information on the instructor with the longest name.
const instructorWithLongestName = function(instructors) {
//tracks the longest name instructor
let longestNameIndex = 0;
//goes through all the instructors
for (let i = 0; i < instructors.length; i++){
if (instructors[i].name.length > instructors[longestNameIndex].name.length){
longestNameIndex = i;
}
}
return instructors[longestNameIndex];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment