sort-indexes

3.0.0 • Public • Published

sort-indexes

Sorts the elements of an array and returns a new array with the indexes of the elements from the original array in sorted order.

Usage

sortIndexes(array[, comparator])

Parameters

  • array the array to sort.
  • comparator (optional) function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.
    • firstEl The first element for comparison.
    • secondEl The second element for comparison.

Return value

A new array containing the indexes of array in the sorted order.

Examples

import sortIndexes from 'sort-indexes';

sortIndexes(['c', 'a', 'b']); // -> [2, 0, 1]

sortIndexes([5, 1, 3, 4, 2], (a, b) => b - a); // -> [0, 3, 2, 4, 1]

Package Sidebar

Install

npm i sort-indexes

Weekly Downloads

0

Version

3.0.0

License

MIT

Unpacked Size

4.87 kB

Total Files

6

Last publish

Collaborators

  • jacobbuck