From ce5468ff9fb6385f20f30486f173a505d61e75af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Thu, 5 Dec 2024 17:26:09 +0800 Subject: [PATCH] Update iterable.md --- docs/uts/buildin-object-api/iterable.md | 72 +++++++++++++------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/docs/uts/buildin-object-api/iterable.md b/docs/uts/buildin-object-api/iterable.md index 28c77f62..f4d8172a 100644 --- a/docs/uts/buildin-object-api/iterable.md +++ b/docs/uts/buildin-object-api/iterable.md @@ -226,25 +226,25 @@ for (item of test) { ```typescript class TestClass implements UTSValueIterable { - - holderArray: (any | null)[] = [11, 22, null, 33, 44, null] - - valueIterator(): UTSIterator { - let holderIndex = 0; - let obj: UTSIterator = { - - next: () : UTSIteratorResult => { - const done = holderIndex == this.holderArray.length - return { - done, - value: done ? null : this.holderArray[holderIndex++], - } as UTSIteratorResult + + holderArray: (any | null)[] = [11, 22, null, 33, 44, null] + + valueIterator(): UTSIterator { + let holderIndex = 0; + let obj: UTSIterator = { + + next: () : UTSIteratorResult => { + const done = holderIndex == this.holderArray.length + return { + done, + value: done ? null : this.holderArray[holderIndex++], + } as UTSIteratorResult + } } + return obj } - return obj + } - -} ``` 执行结果: @@ -268,28 +268,30 @@ item null ```typescript -class TestClass implements UTSValueIterable { - - holderArray: (any | null)[] = [11, 22, null, 33, 44, null] - - valueIterator(): UTSIterator { - let holderIndex = 0; - let arr = this.holderArray.filter((value) => { - return value != null - }) - - let obj: UTSIterator = { - next: () : UTSIteratorResult => { - const done = holderIndex == arr.length - return { - done, - value: done ? null : arr[holderIndex++], - } as UTSIteratorResult + class TestClass implements UTSValueIterable { + + holderArray: (any | null)[] = [11, 22, null, 33, 44, null] + + valueIterator(): UTSIterator { + let holderIndex = 0; + let arr = this.holderArray.filter((value) => { + return value != null + }) + + let obj: UTSIterator = { + + next: () : UTSIteratorResult => { + const done = holderIndex == arr.length + return { + done, + value: done ? null : arr[holderIndex++], + } as UTSIteratorResult + } } + return obj } - return obj + } -} ``` -- GitLab