From 21096c8d0aba4cf68a00b2ce9e3159f0ee27bce4 Mon Sep 17 00:00:00 2001 From: RiverTwilight Date: Thu, 5 Jan 2023 10:27:48 +0800 Subject: [PATCH] lint: added comments --- .../worst_best_time_complexity.js | 4 ++++ .../worst_best_time_complexity.ts | 4 ++++ docs/chapter_computational_complexity/time_complexity.md | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/codes/javascript/chapter_computational_complexity/worst_best_time_complexity.js b/codes/javascript/chapter_computational_complexity/worst_best_time_complexity.js index f887fe28d..791cfe7a2 100644 --- a/codes/javascript/chapter_computational_complexity/worst_best_time_complexity.js +++ b/codes/javascript/chapter_computational_complexity/worst_best_time_complexity.js @@ -4,8 +4,10 @@ * Author: RiverTwilight (contact@rene.wang) */ +/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ function randomNumbers(n) { let nums = Array(n); + // 生成数组 nums = { 1, 2, 3, ..., n } for (let i = 0; i < n; i++) { nums[i] = i + 1; } @@ -19,6 +21,7 @@ function randomNumbers(n) { return nums; } +/* 查找数组 nums 中数字 1 所在索引 */ function findOne(nums) { for (let i = 0; i < nums.length; i++) { if (nums[i] == 1) { @@ -28,6 +31,7 @@ function findOne(nums) { return -1; } +/* Driver Code */ function main() { for (let i = 0; i < 10; i++) { let n = 100; diff --git a/codes/typescript/chapter_computational_complexity/worst_best_time_complexity.ts b/codes/typescript/chapter_computational_complexity/worst_best_time_complexity.ts index 97ca003a1..68ed9bc35 100644 --- a/codes/typescript/chapter_computational_complexity/worst_best_time_complexity.ts +++ b/codes/typescript/chapter_computational_complexity/worst_best_time_complexity.ts @@ -4,8 +4,10 @@ * Author: RiverTwilight (contact@rene.wang) */ +/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ function randomNumbers(n: number): number[] { let nums = Array(n); + // 生成数组 nums = { 1, 2, 3, ..., n } for (let i = 0; i < n; i++) { nums[i] = i + 1; } @@ -19,6 +21,7 @@ function randomNumbers(n: number): number[] { return nums; } +/* 查找数组 nums 中数字 1 所在索引 */ function findOne(nums: number[]): number { for (let i = 0; i < nums.length; i++) { if (nums[i] == 1) { @@ -28,6 +31,7 @@ function findOne(nums: number[]): number { return -1; } +/* Driver Code */ function main(): void { for (let i = 0; i < 10; i++) { let n = 100; diff --git a/docs/chapter_computational_complexity/time_complexity.md b/docs/chapter_computational_complexity/time_complexity.md index 815424dd3..db2c5614d 100644 --- a/docs/chapter_computational_complexity/time_complexity.md +++ b/docs/chapter_computational_complexity/time_complexity.md @@ -2328,8 +2328,10 @@ $$ === "JavaScript" ```js title="worst_best_time_complexity.js" + /* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ function randomNumbers(n) { let nums = Array(n); + // 生成数组 nums = { 1, 2, 3, ..., n } for (let i = 0; i < n; i++) { nums[i] = i + 1; } @@ -2343,6 +2345,7 @@ $$ return nums; } + /* 查找数组 nums 中数字 1 所在索引 */ function findOne(nums) { for (let i = 0; i < nums.length; i++) { if (nums[i] == 1) { @@ -2352,6 +2355,7 @@ $$ return -1; } + /* Driver Code */ function main() { for (let i = 0; i < 10; i++) { let n = 100; @@ -2368,8 +2372,10 @@ $$ === "TypeScript" ```typescript title="worst_best_time_complexity.ts" + /* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ function randomNumbers(n: number): number[] { let nums = Array(n); + // 生成数组 nums = { 1, 2, 3, ..., n } for (let i = 0; i < n; i++) { nums[i] = i + 1; } @@ -2383,6 +2389,7 @@ $$ return nums; } + /* 查找数组 nums 中数字 1 所在索引 */ function findOne(nums: number[]): number { for (let i = 0; i < nums.length; i++) { if (nums[i] == 1) { @@ -2392,6 +2399,7 @@ $$ return -1; } + /* Driver Code */ function main(): void { for (let i = 0; i < 10; i++) { let n = 100;