3
Performs a multi-level three-way comparison on numbers/strings and returns 1, 0, or -1.
Primarily useful in complex sort()
callbacks.
Installation
npm install 3 --save
Usage
const compare3Way = const people = name: 'John' age: 27 name: 'Stephen' age: 26 name: 'John' age: 25 // Sort by namepeople // John, John, Stephen // Sort by agepeople // John, Stephen, John // Multi-level sort: First by name, then by agepeople // John (#2), John (#1), Stephen // Normally empty strings are sorted so they come first,// but you can use the `emptyStringsLast` option to change that. // -1 // 1