sort-array-by-another
v1.1.0
Published
Sort an array, then apply the same steps to another array.
Downloads
4
Maintainers
Readme
sort-array-by-another
Sort an array, then apply the same steps to another array.
Installing
npm install sort-array-by-another
Usage
Let's assume we have arrays of properties:
const names = ['boris', 'ada', 'charles']
const student = [false, true, true]
const ages = [20, 10, 30]
For performance reasons, we won't use an array of objects, but use sort-array-by-another
instead:
const recordSort = require('sort-array-by-another')
const applySort = recordSort(ages)
applySort(student)
// [true, false, true]
applySort(names)
// ['ada', 'boris', 'charles']
Using sortArrayByAnother
, you can sort items
the same way that Array.prototype.sort
will sort model
:
Related
array-rearrange
– Rearrange array elements by index.
Contributing
If you have a question or have difficulties using `sort-arrays-by-another, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.