From 34766f50eb0877f0e469a4e2af814ceecc03ba15 Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Wed, 4 Sep 2024 13:07:10 +0800 Subject: [PATCH] =?UTF-8?q?[array]=E5=8E=BB=E9=99=A4=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E4=BB=A3=E7=A0=81(=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E6=96=B9=E6=B3=95=E4=B8=8B=E9=9D=A2=E7=9A=84=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/Array.uts | 45 +++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/uni_modules/uts-tests/utssdk/Array.uts b/uni_modules/uts-tests/utssdk/Array.uts index bfa9b9f..f2d0c9e 100644 --- a/uni_modules/uts-tests/utssdk/Array.uts +++ b/uni_modules/uts-tests/utssdk/Array.uts @@ -548,7 +548,7 @@ export function testArray() : Result { test("unshift", () => { // #TEST Array.unshift const array1 = [1, 2, 3]; - let ret1 =array1.unshift(4, 5) + let ret1 = array1.unshift(4, 5) console.log(ret1); // 5 @@ -742,6 +742,49 @@ export function testArray() : Result { console.log(shallowCopy) // ["Strawberry", "Mango"] // #END + // #TEST Array.sampleForEachCallback + let array = ['a', 'b', 'c']; + array.forEach(element => { + console.log(element) + // array.pop() // 此行为在 Android 平台会造成闪退,在 iOS 平台会输出 'a', 'b', 'c', 而 JS 会输出 'a', 'b' + }); + + // 如果想让上述行为正常运行,可以用 while 循环实现: + + array = ['a', 'b', 'c']; + let index = 0; + while (index < array.length) { + console.log(array[index]); + array.pop(); + index += 1; + } + // #END + + // #TEST Array.sampleSort + // #ifdef APP-ANDROID + let a = [2, 0, 4]; + a.sort((a, b) : number => { + // 这里的判断不能省略 + if (a.compareTo(b) == 0) { + return 0 + } + return a - b + }) + // #endif + + // #END + + // #TEST Array.sampleFill + let b = new Array() + for (let i = 0; i < 20; i++) { + b.push(0) + } + // #END + + // #TEST Array.sampleFillError + new Array(20).fill(0) + // #END + }) }) -- GitLab