@suninfo/array-is-sorted

0.1.0 • Public • Published

array-is-sorted

检测数组是否排序的模块

Installation

$ npm install @sunflower/array-is-sorted

Usage

默认的排序规则为由小到大。

const checksorted = require('@sunflower/array-is-sorted');

checksorted([1, 3, 5]); // => true
checksorted([3, 1, 5]); // => false

自定义排序规则

const checksorted = require('@sunflower/array-is-sorted');

let myfun = function(prev, next) {
  return next.charCodeAt() - prev.charCodeAt()
};

checksorted(['a', 'b', 'f'], myfun); // => true
checksorted(['c', 'z', 'm'], myfun); // => false

Tests

安装mocha测试框架,然后执行测试命令:

$ yarn
$ npm test

License

The MIT License

Package Sidebar

Install

npm i @suninfo/array-is-sorted

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

8.6 kB

Total Files

7

Last publish

Collaborators

  • fighting123
  • xhlf