lint: added comments

This commit is contained in:
RiverTwilight 2023-01-05 10:27:48 +08:00
parent c53f64d56b
commit 21096c8d0a
3 changed files with 16 additions and 0 deletions

View file

@ -4,8 +4,10 @@
* Author: RiverTwilight (contact@rene.wang) * Author: RiverTwilight (contact@rene.wang)
*/ */
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n) { function randomNumbers(n) {
let nums = Array(n); let nums = Array(n);
// 生成数组 nums = { 1, 2, 3, ..., n }
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
nums[i] = i + 1; nums[i] = i + 1;
} }
@ -19,6 +21,7 @@ function randomNumbers(n) {
return nums; return nums;
} }
/* 查找数组 nums 中数字 1 所在索引 */
function findOne(nums) { function findOne(nums) {
for (let i = 0; i < nums.length; i++) { for (let i = 0; i < nums.length; i++) {
if (nums[i] == 1) { if (nums[i] == 1) {
@ -28,6 +31,7 @@ function findOne(nums) {
return -1; return -1;
} }
/* Driver Code */
function main() { function main() {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let n = 100; let n = 100;

View file

@ -4,8 +4,10 @@
* Author: RiverTwilight (contact@rene.wang) * Author: RiverTwilight (contact@rene.wang)
*/ */
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n: number): number[] { function randomNumbers(n: number): number[] {
let nums = Array(n); let nums = Array(n);
// 生成数组 nums = { 1, 2, 3, ..., n }
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
nums[i] = i + 1; nums[i] = i + 1;
} }
@ -19,6 +21,7 @@ function randomNumbers(n: number): number[] {
return nums; return nums;
} }
/* 查找数组 nums 中数字 1 所在索引 */
function findOne(nums: number[]): number { function findOne(nums: number[]): number {
for (let i = 0; i < nums.length; i++) { for (let i = 0; i < nums.length; i++) {
if (nums[i] == 1) { if (nums[i] == 1) {
@ -28,6 +31,7 @@ function findOne(nums: number[]): number {
return -1; return -1;
} }
/* Driver Code */
function main(): void { function main(): void {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let n = 100; let n = 100;

View file

@ -2328,8 +2328,10 @@ $$
=== "JavaScript" === "JavaScript"
```js title="worst_best_time_complexity.js" ```js title="worst_best_time_complexity.js"
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n) { function randomNumbers(n) {
let nums = Array(n); let nums = Array(n);
// 生成数组 nums = { 1, 2, 3, ..., n }
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
nums[i] = i + 1; nums[i] = i + 1;
} }
@ -2343,6 +2345,7 @@ $$
return nums; return nums;
} }
/* 查找数组 nums 中数字 1 所在索引 */
function findOne(nums) { function findOne(nums) {
for (let i = 0; i < nums.length; i++) { for (let i = 0; i < nums.length; i++) {
if (nums[i] == 1) { if (nums[i] == 1) {
@ -2352,6 +2355,7 @@ $$
return -1; return -1;
} }
/* Driver Code */
function main() { function main() {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let n = 100; let n = 100;
@ -2368,8 +2372,10 @@ $$
=== "TypeScript" === "TypeScript"
```typescript title="worst_best_time_complexity.ts" ```typescript title="worst_best_time_complexity.ts"
/* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */
function randomNumbers(n: number): number[] { function randomNumbers(n: number): number[] {
let nums = Array(n); let nums = Array(n);
// 生成数组 nums = { 1, 2, 3, ..., n }
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
nums[i] = i + 1; nums[i] = i + 1;
} }
@ -2383,6 +2389,7 @@ $$
return nums; return nums;
} }
/* 查找数组 nums 中数字 1 所在索引 */
function findOne(nums: number[]): number { function findOne(nums: number[]): number {
for (let i = 0; i < nums.length; i++) { for (let i = 0; i < nums.length; i++) {
if (nums[i] == 1) { if (nums[i] == 1) {
@ -2392,6 +2399,7 @@ $$
return -1; return -1;
} }
/* Driver Code */
function main(): void { function main(): void {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let n = 100; let n = 100;