Add TypeScript code and docs to AVL tree and the coding style for Typescript and JavaScript (#342)

* Add TypeScript code and docs to AVL tree and update JavaScript style

* Update the coding style for Typescript and JavaScript
This commit is contained in:
Justin Tse
2023-02-07 01:21:58 +08:00
committed by GitHub
parent 7f4243ab77
commit b14568151c
9 changed files with 453 additions and 49 deletions

View File

@ -2555,7 +2555,7 @@ $$
```js title="worst_best_time_complexity.js"
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n) {
let nums = Array(n);
const nums = Array(n);
// 生成数组 nums = { 1, 2, 3, ..., n }
for (let i = 0; i < n; i++) {
nums[i] = i + 1;
@ -2588,15 +2588,15 @@ $$
```typescript title="worst_best_time_complexity.ts"
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n: number): number[] {
let nums = Array(n);
const nums = Array(n);
// 生成数组 nums = { 1, 2, 3, ..., n }
for (let i = 0; i < n; i++) {
nums[i] = i + 1;
}
// 随机打乱数组元素
for (let i = 0; i < n; i++) {
let r = Math.floor(Math.random() * (i + 1));
let temp = nums[i];
const r = Math.floor(Math.random() * (i + 1));
const temp = nums[i];
nums[i] = nums[r];
nums[r] = temp;
}