array-sortindex

Get sorted indexes of array (using insertion sort).

Usage no npm install needed!

<script type="module">
  import arraySortindex from 'https://cdn.skypack.dev/array-sortindex';
</script>

README

array-sortindex

NOTE: array-sortindex was renamed to @extra-array/sort-index. NPM

Get sorted indexes of array (using insertion sort).

const sortIndex = require('array-sortindex');
// sortIndex(<array>, [compare function], [this], [begin=0], [end], [target=[]], [at])
// -> <target>

sortIndex([6, 1, 9, 20, 8]);
// [1, 0, 4, 2, 3]
sortIndex(['N', 'o', 'a', 'h'], (a, b) => a.localeCompare(b));
// [2, 3, 0, 1]
sortIndex(['B', 'i', 'r', 'd', 'm', 'a', 'n'], (a, b) => a.localeCompare(b), null);
// [5, 0, 3, 1, 4, 6, 2]
sortIndex(['E', 'd', 'g', 'e'], null, null, 1);
// [1, 3, 2]
sortIndex(['E', 'd', 'g', 'e'], null, null, 1, 3);
// [1, 2]
sortIndex(['E', 'd', 'g', 'e'], null, null, 1, 3, [10, 11]);
// [10, 11, 1, 2]
sortIndex(['E', 'd', 'g', 'e'], null, null, 1, 3, [10, 11], 1);
// [10, 1, 2]