Skip to content

Instantly share code, notes, and snippets.

@madeleine68
Created September 4, 2021 05:53
Show Gist options
  • Save madeleine68/7f5db6af6f39567223db01fd6e81598d to your computer and use it in GitHub Desktop.
Save madeleine68/7f5db6af6f39567223db01fd6e81598d to your computer and use it in GitHub Desktop.
const instructorWithLongestName = function(instructors) {
let sorted = instructors.sort(function(a, b) {
return b.name.length - a.name.length;
});
return sorted[0];
};
console.log(instructorWithLongestName([
{name: "Samuel", course: "iOS"},
{name: "Jeremiah", course: "Web"},
{name: "Ophilia", course: "Web"},
{name: "Donald", course: "Web"}
]));
console.log(instructorWithLongestName([
{name: "Matthew", course: "Web"},
{name: "David", course: "iOS"},
{name: "Domascus", course: "Web"}
]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment