multi-sort
Multidimensional Sort Helper
Installation
With npm:
$ npm i multi-sort
or with yarn:
$ yarn add multi-sort
Usage
import MultiSort from 'multi-sort';
let arr = [
{ first_name: 'John', last_name: 'Doe' },
{ first_name: 'Anthony', last_name: 'Zipher' },
{ first_name: 'Anthony', last_name: 'Carlos' }
];
let sortedByFirstName = MultiSort(arr, 'first_name', 'ASC');
/* Sort by multi params */
let sortedByFirstAndLast = MultiSort(arr, ['first_name', 'last_name'], ['ASC', 'DESC']);
/* or */
let sortedByFirstAndLast = MultiSort(arr, {
first_name: 'ASC',
last_name: 'DESC'
});