This commit is contained in:
krahets
2023-02-08 16:47:52 +08:00
parent 139e34bdb1
commit 7156a5f832
15 changed files with 367 additions and 208 deletions
+22
View File
@@ -1195,6 +1195,17 @@ comments: true
// 更新列表容量
this.#capacity = this.#nums.length;
}
/* 将列表转换为数组 */
toArray() {
let size = this.size();
// 仅转换有效长度范围内的列表元素
const nums = new Array(size);
for (let i = 0; i < size; i++) {
nums[i] = this.get(i);
}
return nums;
}
}
```
@@ -1289,6 +1300,17 @@ comments: true
// 更新列表容量
this._capacity = this.nums.length;
}
/* 将列表转换为数组 */
public toArray(): number[] {
let size = this.size();
// 仅转换有效长度范围内的列表元素
let nums = new Array(size);
for (let i = 0; i < size; i++) {
nums[i] = this.get(i);
}
return nums;
}
}
```