mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
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:
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user