mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	Apply suggestions from code review
Co-authored-by: Justin Tse <xiefahit@gmail.com>
This commit is contained in:
		@ -13,7 +13,7 @@ function randomNumbers(n) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    // 随机打乱数组元素
 | 
					    // 随机打乱数组元素
 | 
				
			||||||
    for (let i = 0; i < n; i++) {
 | 
					    for (let i = 0; i < n; i++) {
 | 
				
			||||||
        let r = Math.floor(Math.random() * n);
 | 
					        let r = Math.floor(Math.random() * (i + 1));
 | 
				
			||||||
        let temp = nums[i];
 | 
					        let temp = nums[i];
 | 
				
			||||||
        nums[i] = nums[r];
 | 
					        nums[i] = nums[r];
 | 
				
			||||||
        nums[r] = temp;
 | 
					        nums[r] = temp;
 | 
				
			||||||
@ -24,7 +24,7 @@ function randomNumbers(n) {
 | 
				
			|||||||
/* 查找数组 nums 中数字 1 所在索引 */
 | 
					/* 查找数组 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) {
 | 
				
			||||||
            return i;
 | 
					            return i;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ function randomNumbers(n: number): number[] {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    // 随机打乱数组元素
 | 
					    // 随机打乱数组元素
 | 
				
			||||||
    for (let i = 0; i < n; i++) {
 | 
					    for (let i = 0; i < n; i++) {
 | 
				
			||||||
        let r = Math.floor(Math.random() * n);
 | 
					        let r = Math.floor(Math.random() * (i + 1));
 | 
				
			||||||
        let temp = nums[i];
 | 
					        let temp = nums[i];
 | 
				
			||||||
        nums[i] = nums[r];
 | 
					        nums[i] = nums[r];
 | 
				
			||||||
        nums[r] = temp;
 | 
					        nums[r] = temp;
 | 
				
			||||||
@ -24,7 +24,7 @@ function randomNumbers(n: number): number[] {
 | 
				
			|||||||
/* 查找数组 nums 中数字 1 所在索引 */
 | 
					/* 查找数组 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) {
 | 
				
			||||||
            return i;
 | 
					            return i;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user