From 55a5055db3a0e3bb4468d05adcda450a375e1eb1 Mon Sep 17 00:00:00 2001 From: yigencong Date: Thu, 22 Feb 2024 23:05:56 +0800 Subject: [PATCH] =?UTF-8?q?feta:=20=E6=B7=BB=E5=8A=A0=E5=87=BD=E6=95=B0isS?= =?UTF-8?q?ort(=E5=88=A4=E6=96=AD=E6=95=B0=E7=BB=84=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E5=BA=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/index.mjs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/util/index.mjs b/util/index.mjs index 861ae76..3868ef2 100644 --- a/util/index.mjs +++ b/util/index.mjs @@ -70,5 +70,28 @@ export function swap(array, a, b) { } - - + export function isSort(arr) { + const len = arr.length + let isInverted = false + if(len <2) { + return true + } + // 判断数组是否倒序 + if(arr[0] > arr[1]) { + isInverted = true + } + if(isInverted) { + for(let i=0;iarr[i+1]){ + return false + } + } + } + return true + }