2 var ensurePojo
= require('./ensure-pojo');
3 // @const - higher index in array, higher rank
4 var RANK
= ['contributor', 'admin'];
6 function compareRank(a
, b
) {
7 return RANK
.indexOf(a
.role
) - RANK
.indexOf(b
.role
) || 0;
10 function compareNames(a
, b
) {
11 return b
.username
.toLowerCase().localeCompare(a
.username
.toLowerCase());
14 // it is worth noticing that we want to sort in a descindencing order, thus the negative results
15 module
.exports = function(a
, b
) {
16 // normalizing Backbone.Model to POJO
20 var rankDifference
= compareRank(a
, b
); // checks if there is rank difference
22 // attempts to sort by rank
24 return -rankDifference
;
28 return -compareNames(a
, b
);