Update the coding style for JavaScript (#329)

* Fix bug before commit 5eae708

* Update queue.md

* Update the coding style for JavaScript

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
Justin Tse
2023-02-05 15:40:30 +08:00
committed by GitHub
parent 6778557056
commit 6ad8a66a7c
8 changed files with 82 additions and 87 deletions

View File

@ -13,8 +13,8 @@ function randomNumbers(n) {
}
// 随机打乱数组元素
for (let i = 0; i < n; i++) {
let r = Math.floor(Math.random() * (i + 1));
let temp = nums[i];
const r = Math.floor(Math.random() * (i + 1));
const temp = nums[i];
nums[i] = nums[r];
nums[r] = temp;
}
@ -34,14 +34,12 @@ function findOne(nums) {
}
/* Driver Code */
function main() {
for (let i = 0; i < 10; i++) {
let n = 100;
let nums = randomNumbers(n);
let index = findOne(nums);
console.log(
"\n数组 [ 1, 2, ..., n ] 被打乱后 = [" + nums.join(", ") + "]"
);
console.log("数字 1 的索引为 " + index);
}
for (let i = 0; i < 10; i++) {
const n = 100;
const nums = randomNumbers(n);
const index = findOne(nums);
console.log(
"\n数组 [ 1, 2, ..., n ] 被打乱后 = [" + nums.join(", ") + "]"
);
console.log("数字 1 的索引为 " + index);
}