sort

Benchmark created on


Setup

const channels = [
    {
        "source": "TELEGRAM",
        "state": false,
        "allowed": false
    },
    {
        "source": "EMAIL",
        "state": true,
        "allowed": true
    },
    {
        "source": "LK",
        "state": true,
        "allowed": true
    },
    {
        "source": "SMS",
        "state": false,
        "allowed": false
    }
];

const COLUMN_ORDER = ["SMS", "TELEGRAM", "EMAIL", "SMS"];

Test runner

Ready to run.

Testing in
TestOps/sec
reduce + map
const channelLookup = channels.reduce((lookup, channel) => {
          lookup[channel.source] = channel;
          return lookup;
        }, {});

const sortedChannels = COLUMN_ORDER.map(source => channelLookup[source]);
ready
sort
const sortedChannels = channels.sort(
          (a, b) => COLUMN_ORDER.indexOf(a.source) - COLUMN_ORDER.indexOf(b.source),
        );
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.