JSPM

  • Created
  • Published
  • Downloads 19
  • Score
    100M100P100Q45825F
  • License MIT

takes an array of arrays full of zero or more integers, sorts by any column

Package Exports

  • array-of-arrays-sort-by-col

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-of-arrays-sort-by-col) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array-of-arrays-sort-by-col

takes an array of arrays full of zero or more integers, sorts by any column

Minimum Node version required Build Status Coverage bitHound Overall Score bitHound Dependencies View dependencies as 2D chart bitHound Dev Dependencies Known Vulnerabilities Downloads/Month Test in browser Code style: prettier MIT License

Install

npm i array-of-arrays-sort-by-col
// consume as CommonJS require():
const sortByCol = require("array-of-arrays-sort-by-col");
// or as ES Module:
import sortByCol from "array-of-arrays-sort-by-col";

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/array-of-arrays-sort-by-col.cjs.js 2 KB
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/array-of-arrays-sort-by-col.esm.js 2 KB
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/array-of-arrays-sort-by-col.umd.js 11 KB

⬆  back to top

Table of Contents

What it does

Sorts by any column (default is first element, zero'th column index).

Input:

[[1, 9, 0], [1], [1, 8, 2], [1, 7, 5]];

Output: [[1, 7, 5], [1, 8, 2], [1, 9, 0], [1]];

Rules:

  • Input must be an array of zero or more arrays full of zero or more numbers
  • If an index of a current column we're matching on is the same between two rows, we jump to next column and so on
  • Row without particular value in the column goes to the bottom (like in the example above)

⬆  back to top

Sorting by certain column

For example, let's sort this array by second element (column index = 1):

const sortByCol = require("array-of-arrays-sort-by-col");
const input = [[1, 9, 0], [1], [1, 8, 2], [1, 7, 5]];
const result = sortByCol(input, 1);
console.log(
  `${`\u001b[${33}m${`input`}\u001b[${39}m`} = ${JSON.stringify(
    input,
    null,
    0
  )}`
);
// => input = [[1, 7, 5], [1, 8, 2], [1, 9, 0], [1]],

⬆  back to top

API

sortByCol (arr, [index])

API - Input

Input argument Type Obligatory? Description
arr Array of zero or more arrays yes Source of data to put into an AST
index Natural number or zero, like a number or string no By which column should we match the subarrays (rows)? The default is 0 or the first element of each sub-array.

⬆  back to top

API - Output

Type Description
Array of arrays Same thing as input but sorted (if given not empty)

⬆  back to top

Contributing

  • If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.

  • If you tried to use this library but it misbehaves, or you need advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Prettier is enabled, so you don't need to worry about the code style.

⬆  back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt