Sort input array, return sorted ids of the array items, keeping the initial array unchanged.
Useful to perform linked sorting of multiple arrays, where linked array[s] should be sorted the same way as the primary one.
var sort =var reorder =var rates = 12 47 52 97 ...sourceNumbersvar names = 'John' 'Alexa' 'Jimmy' 'Kate' ...linkedItemsvar ids =var sortedRates =var sortedNames =
ids = sortIds(array, ids?, precise=true)
Calculate ids corresponding to sorted input array. Optionally pass input
precise flag makes sure no missorts took place and resolves them, if any. Disabling that can save
1e6 items input arrays.
See also array-rearrange for reordering input array based on a list of ids.
This package is >= 6 times faster compared to sorting function. That is achieved by packing input
value - id pairs into a single
float64 value and performing native sort on that Float64Array, then unpacking the
(c) 2018 Dmitry Yv. MIT License