判断number[]数组中元素是由小到大或者是由大到小
- npm i sx-is-sorted
- import sxIsSorted from "sx-is-sorted"
import sxIsSorted from "sx-is-sorted";
// 第一个参数number[],第二个参数默认为true,数组中元素是否由小到大
console.log(sxIsSorted([1, 2, 3, 4, 5])); // 返回 true
console.log(sxIsSorted([1, 2, 3, 5, 4])); // 返回 false
// 第一个参数number[],第二个参数为false,数组中元素是否由大到小
console.log(sxIsSorted([5, 4, 3, 2, 1], false)); // 返回 true
console.log(sxIsSorted([4, 5, 3, 2, 1], false)); // 返回 false