sort-array-by-another

1.1.0 • Public • Published

sort-array-by-another

Sort an array, then apply the same steps to another array.

npm version build status ISC-licensed chat with me on Gitter support me on Patreon

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

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.

Package Sidebar

Install

npm i sort-array-by-another

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

3.92 kB

Total Files

4

Last publish

Collaborators

  • derhuerst