array-of-arrays-sort-by-col examples

Table of Contents

Quick Take

import { strict as assert } from "assert";
import { sortByCol } from "array-of-arrays-sort-by-col";

// sort by second column, index number 1
assert.deepEqual(
  sortByCol([[1, 9, 4], [1], [1, 9, 3], [1, 9, 2]], 1),
  [[1, 9, 2], [1, 9, 3], [1, 9, 4], [1]]
);

Sort by a certain column

import { strict as assert } from "assert";
import { sortByCol } from "array-of-arrays-sort-by-col";

// Sort by a second element (column index === 1):
assert.deepEqual(
  sortByCol([[1, 9, 0], [1], [1, 8, 2], [1, 7, 5]], 1),
  [[1, 7, 5], [1, 8, 2], [1, 9, 0], [1]]
);
// notice 7-8-9