Exercise: Sorting a Collection

Apply what you’ve learned about sorting a collection with functions in Marionette.

Sorting a collection with a function

Let’s say we have the following collection:

Press + to interact
var contacts = new ContactManager.ContactCollection([
{
firstName: "Alice",
lastName: "Tampen"
},
{
firstName: "Bob",
lastName: "Brigham"
},
firstName: "Alice",
lastName: "Artsy"
},
{
firstName: "Alice",
lastName: "Arten"
},
{
firstName: "Charlie",
lastName: "Campbell"
},
{
firstName: "Alice",
lastName: "Smith"
},
]);

If you run the code, you’ll see the contacts in the following order:

    ...