From b7bd8168debe629fe059299070e4493e492faa5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Tue, 30 Jan 2024 19:33:47 +0800 Subject: [PATCH] Update array.md --- docs/uts/buildin-object-api/array.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/uts/buildin-object-api/array.md b/docs/uts/buildin-object-api/array.md index d4264ca7..84c06871 100644 --- a/docs/uts/buildin-object-api/array.md +++ b/docs/uts/buildin-object-api/array.md @@ -302,6 +302,22 @@ array2.sort((a: number, b: number):number => a - b); +**平台差异性** + +在android平台,一定不能忽略两个对比元素相等的场景,否则可能会出现`java.lang.IllegalArgumentException: Comparison method violates its general contract!‌` +``` + +a.sort((a, b) : number => { + // 这里的判断不能省略 + if(a.compareTo(b) == 0){ + return 0 + } + return a - b +}) +``` + + + ### splice(start, deleteCount, ...items) -- GitLab