Acme.BookStore.HttpApi.Host/node_modules/default-compare/README.md
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
# default-compare [](https://www.npmjs.com/package/default-compare) [](https://npmjs.org/package/default-compare) [](https://npmjs.org/package/default-compare) [](https://travis-ci.org/doowb/default-compare) [](https://ci.appveyor.com/project/doowb/default-compare)
> Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save default-compare
```
Install with [yarn](https://yarnpkg.com):
```sh
$ yarn add default-compare
```
## Usage
```js
var defaultCompare = require('default-compare');
```
**basic array**
```js
var arr = ['c', 'a', undefined, 'b', 'd', null, 'e'];
console.log(arr.sort(defaultCompare));
//=> ['a', 'b', 'c', 'd', 'e', null, undefined]
```
**objects sorted by their "name" property**
```js
var arr = [
{name: 'c', title: 'C'},
{name: 'a', title: 'A'},
{title: 'G'},
{name: 'b', title: 'B'},
{name: 'd', title: 'D'},
{name: null, title: 'F'},
{name: 'e', title: 'E'}
];
arr.sort(function(a, b) {
return defaultCompare(a, b, 'name');
});
console.log(arr);
//=> [
//=> {name: 'a', title: 'A'},
//=> {name: 'b', title: 'B'},
//=> {name: 'c', title: 'C'},
//=> {name: 'd', title: 'D'},
//=> {name: 'e', title: 'E'},
//=> {name: null, title: 'F'},
//=> {title: 'G'}
//=> ];
```
后面还有 56 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
