JSFiddle - React, Tailwind, and code Playground
JavaScript
var results = [
{
url : '/',
matches: {
title : false,
h1 : false,
copy : 2
}
},
{
url : '/?id=2',
matches: {
title : true,
h1 : true,
copy : 0
}
},
{
url : '/id=3',
matches: {
title : false,
h1 : false,
copy : 6
}
},
{
url : '/id=3',
matches: {
title : false,
h1 : false,
copy : 7
}
}
];
results = results.sort(function(a, b) {
return a.matches.title && !b.matches.title ? -1
: !a.matches.title && b.matches.title ? 1
: a.matches.h1 && !b.matches.h1 ? -1
: !a.matches.h1 && b.matches.h1 ? 1
: b.matches.copy - a.matches.copy;
});
console.log(results);