JSFiddle - React, Tailwind, and code Playground

by Allie Yu

JavaScript

const data = [
    {
        name: "ABC",
        score: 24
    },
    {
        name: "XYZ",
        score: 48
    },
    {
        name: "PQR",
        score: null
    },
    {
        name: "JKL",
        score: 36
    }
]


var sortByData = function (property){
    return function (x,y) {
        return ((x[property] === y[property] ? 0: (x[property] > y[property]) ? 1:-1));
    };
};

console.log(sortByData(data))