mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 12:36:30 +08:00
Apply suggestions from code review
Co-authored-by: Justin Tse <xiefahit@gmail.com>
This commit is contained in:
parent
21096c8d0a
commit
e96272a06f
2 changed files with 4 additions and 4 deletions
|
@ -13,7 +13,7 @@ function randomNumbers(n) {
|
|||
}
|
||||
// 随机打乱数组元素
|
||||
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];
|
||||
nums[i] = nums[r];
|
||||
nums[r] = temp;
|
||||
|
@ -24,7 +24,7 @@ function randomNumbers(n) {
|
|||
/* 查找数组 nums 中数字 1 所在索引 */
|
||||
function findOne(nums) {
|
||||
for (let i = 0; i < nums.length; i++) {
|
||||
if (nums[i] == 1) {
|
||||
if (nums[i] === 1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ function randomNumbers(n: number): number[] {
|
|||
}
|
||||
// 随机打乱数组元素
|
||||
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];
|
||||
nums[i] = nums[r];
|
||||
nums[r] = temp;
|
||||
|
@ -24,7 +24,7 @@ function randomNumbers(n: number): number[] {
|
|||
/* 查找数组 nums 中数字 1 所在索引 */
|
||||
function findOne(nums: number[]): number {
|
||||
for (let i = 0; i < nums.length; i++) {
|
||||
if (nums[i] == 1) {
|
||||
if (nums[i] === 1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue