Apply suggestions from code review

Co-authored-by: Justin Tse <xiefahit@gmail.com>
This commit is contained in:
Yudong Jin 2023-01-06 03:14:52 +08:00 committed by GitHub
parent 21096c8d0a
commit e96272a06f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -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;
} }
} }

View File

@ -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;
} }
} }