1.1.0 • Published 4 years ago

sort-array-by-another v1.1.0

Weekly downloads
16
License
ISC
Repository
github
Last release
4 years ago

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.

1.1.0

4 years ago

1.0.0

4 years ago

0.1.0

6 years ago