From 420c09789a0fe410ac54a88b5a76b803c9d38219 Mon Sep 17 00:00:00 2001 From: bi-hu Date: Tue, 28 Feb 2023 18:32:18 +0800 Subject: [PATCH] Modify the problem of printing test cases of the foreach interface in containers to 3.1-Release Signed-off-by: bi-hu --- .../reference/apis/js-apis-arraylist.md | 10 ++-- .../reference/apis/js-apis-deque.md | 2 +- .../reference/apis/js-apis-hashmap.md | 2 +- .../reference/apis/js-apis-hashset.md | 2 +- .../reference/apis/js-apis-lightweightmap.md | 2 +- .../reference/apis/js-apis-lightweightset.md | 2 +- .../reference/apis/js-apis-linkedlist.md | 2 +- .../reference/apis/js-apis-list.md | 2 +- .../reference/apis/js-apis-plainarray.md | 2 +- .../reference/apis/js-apis-queue.md | 2 +- .../reference/apis/js-apis-stack.md | 2 +- .../reference/apis/js-apis-treemap.md | 2 +- .../reference/apis/js-apis-treeset.md | 2 +- .../reference/apis/js-apis-vector.md | 46 +++++-------------- 14 files changed, 27 insertions(+), 53 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-arraylist.md b/zh-cn/application-dev/reference/apis/js-apis-arraylist.md index dd9a810be7..311139105e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-arraylist.md +++ b/zh-cn/application-dev/reference/apis/js-apis-arraylist.md @@ -319,11 +319,9 @@ arrayList.add(2); arrayList.add(4); arrayList.add(5); arrayList.add(4); -arrayList.replaceAllElements((value: number, index: number)=> { - return value = 2 * value; -}); -arrayList.replaceAllElements((value: number, index: number) => { - return value = value - 2; +arrayList.replaceAllElements((value) => { + // 用户操作逻辑根据实际场景进行添加。 + return value; }); ``` @@ -360,7 +358,7 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); arrayList.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-deque.md b/zh-cn/application-dev/reference/apis/js-apis-deque.md index 2d9c75c123..055a704265 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-deque.md +++ b/zh-cn/application-dev/reference/apis/js-apis-deque.md @@ -207,7 +207,7 @@ deque.insertEnd(4); deque.insertFront(5); deque.insertEnd(4); deque.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-hashmap.md b/zh-cn/application-dev/reference/apis/js-apis-hashmap.md index 7461764655..af0e9f9f98 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hashmap.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hashmap.md @@ -374,7 +374,7 @@ let hashMap = new HashMap(); hashMap.set("sdfs", 123); hashMap.set("dfsghsf", 357); hashMap.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-hashset.md b/zh-cn/application-dev/reference/apis/js-apis-hashset.md index fd7cf5eeb8..6e94e021fb 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hashset.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hashset.md @@ -227,7 +227,7 @@ let hashSet = new HashSet(); hashSet.add("sdfs"); hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md b/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md index 444b5e783b..75dc7cc022 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md +++ b/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md @@ -581,7 +581,7 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("sdfs", 123); lightWeightMap.set("dfsghsf", 357); lightWeightMap.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md b/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md index a308d35203..03176c4aea 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md +++ b/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md @@ -481,7 +481,7 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("sdfs"); lightWeightSet.add("dfsghsf"); lightWeightSet.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md b/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md index e5a46eae66..ee2c19d821 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md +++ b/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md @@ -495,7 +495,7 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); linkedList.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-list.md b/zh-cn/application-dev/reference/apis/js-apis-list.md index 18e8871473..c701c60a34 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-list.md +++ b/zh-cn/application-dev/reference/apis/js-apis-list.md @@ -404,7 +404,7 @@ list.add(4); list.add(5); list.add(4); list.forEach((value, index) => { - console.log("value: " + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-plainarray.md b/zh-cn/application-dev/reference/apis/js-apis-plainarray.md index b6a81a607c..837d2143e9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-plainarray.md +++ b/zh-cn/application-dev/reference/apis/js-apis-plainarray.md @@ -481,7 +481,7 @@ let plainArray = new PlainArray(); plainArray.add(1, "sddfhf"); plainArray.add(2, "sffdfhf"); plainArray.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-queue.md b/zh-cn/application-dev/reference/apis/js-apis-queue.md index b8d81d54e1..21050cebfb 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-queue.md +++ b/zh-cn/application-dev/reference/apis/js-apis-queue.md @@ -159,7 +159,7 @@ queue.add(4); queue.add(5); queue.add(4); queue.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-stack.md b/zh-cn/application-dev/reference/apis/js-apis-stack.md index 3f8acdad67..03af115626 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-stack.md +++ b/zh-cn/application-dev/reference/apis/js-apis-stack.md @@ -191,7 +191,7 @@ stack.push(4); stack.push(5); stack.push(4); stack.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-treemap.md b/zh-cn/application-dev/reference/apis/js-apis-treemap.md index f0be726bb9..acf65f23cf 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-treemap.md +++ b/zh-cn/application-dev/reference/apis/js-apis-treemap.md @@ -490,7 +490,7 @@ let treeMap = new TreeMap(); treeMap.set("sdfs", 123); treeMap.set("dfsghsf", 357); treeMap.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-treeset.md b/zh-cn/application-dev/reference/apis/js-apis-treeset.md index bce616971a..ed0d6a1cb1 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-treeset.md +++ b/zh-cn/application-dev/reference/apis/js-apis-treeset.md @@ -393,7 +393,7 @@ let treeSet = new TreeSet(); treeSet.add("sdfs"); treeSet.add("dfsghsf"); treeSet.forEach((value, key) => { - console.log("value:" + value, key) + console.log("value:" + value, "key:" + key); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-vector.md b/zh-cn/application-dev/reference/apis/js-apis-vector.md index c57bbca6de..a1e72b0e8c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-vector.md +++ b/zh-cn/application-dev/reference/apis/js-apis-vector.md @@ -1,14 +1,15 @@ # 线性容器Vector -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - Vector是一种线性数据结构,底层基于数组实现。当Vector的内存用尽时,会自动分配更大的连续内存区,将原先的元素复制到新的内存区,并释放旧的内存区。使用Vector能够高效快速地访问元素。 Vector和[ArrayList](js-apis-arraylist.md)相似,都是基于数组实现,但Vector提供了更多操作数组的接口。它们都可以动态调整容量,但Vector每次扩容增加1倍,ArrayList只扩容0.5倍。 **推荐使用场景:** 当数据量大时,一般使用Vector来存取数据。 +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + ## 导入模块 ```ts @@ -247,7 +248,7 @@ remove(element: T): boolean | -------- | -------- | | boolean | 删除成功返回true,否则返回false。 | -**返回值:** +**示例:** ```ts let vector = new Vector(); @@ -318,11 +319,9 @@ vector.add(2); vector.add(4); vector.add(5); vector.add(4); -vector.replaceAllElements((value: number, index: number) => { - return value = 2 * value; -}); -vector.replaceAllElements((value: number, index: number) => { - return value = value - 2; +vector.replaceAllElements((value) => { + // 用户操作逻辑根据实际场景进行添加。 + return value; }); ``` @@ -359,7 +358,7 @@ vector.add(4); vector.add(5); vector.add(4); vector.forEach((value, index) => { - console.log("value:" + value, index) + console.log("value:" + value, "index:" + index); }); ``` @@ -419,7 +418,7 @@ subVector(fromIndex: number, toIndex: number): Vector<T> | -------- | -------- | | Vector<T> | 返回Vector对象实例。 | -**返回值:** +**示例:** ```ts let vector = new Vector(); @@ -441,7 +440,7 @@ clear(): void **系统能力:** SystemCapability.Utils.Lang -**返回值:** +**示例:** ```ts let vector = new Vector(); @@ -636,18 +635,6 @@ copyToArray(array: Array<T>): void | -------- | -------- | -------- | -------- | | array | Array<T> | 是 | 指定数组。 | -**示例:** - -```ts -let vector = new Vector(); -vector.add(2); -vector.add(4); -vector.add(5); -vector.add(4); -let array = ["a", "b", "c", "d", "e", "f"]; -let result = vector.copyToArray(array); -``` - ### getFirstElement getFirstElement(): T @@ -841,17 +828,6 @@ set(index: number, element: T): T | -------- | -------- | | T | 返回替换后的元素。 | -**示例:** - - ```ts - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - let result = vector.set(2, "A"); - ``` - ### [Symbol.iterator] [Symbol.iterator]\(): IterableIterator<T> -- GitLab