JSFiddle - React, Tailwind, and code Playground

by jfriend00

CSS

body {font-family: "Courier New";font-size: 12px;}

JavaScript

var data = [
    {type: 'S', year: 'SW Walker'},
    {type: 'C', year: 'SW Greth'},
    {type: 'S', year: 'SW Karp'},
    {type: 'C', year: 'SW Main'},
    {type: 'H', year: 'SW Dummy'},
    {type: 'X', year: 'Whatever'}  // test out unknown type
];

data.sort(function(a, b) {
    var order = {"S": 1,"C": 2,"H": 3}, typeA, typeB;
    if (a.type != b.type) {
        typeA = order[a.type] || -1;
        typeB = order[b.type] || -1;
        return(typeA - typeB);
    } else {
        return(a.year.localeCompare(b.year));
    }
});

document.body.innerHTML = JSON.stringify(data)
    .replace(/\},\{/g, "},<br>{")
    .replace(/\[\{/g, "[<br>{")
    .replace(/\}\]/g, "}<br>]")
    .replace(/\{/g, "&nbsp;&nbsp;&nbsp;&nbsp;{");