Retranslate the complete Japanese online edition from Chinese (#2008)

* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
This commit is contained in:
Yudong Jin
2026-10-30 02:12:26 +08:00
committed by GitHub
parent 455e8c1281
commit 7257641e0e
1987 changed files with 23531 additions and 23261 deletions
@@ -4,22 +4,22 @@
* Author: IsChristina ([email protected])
*/
/* 要素へランダムアクセス */
/* 要素にランダムアクセスする */
function randomAccess(nums) {
// 区間 [0, nums.length) からランダムに 1 つの数を選ぶ
// 区間 [0, nums.length) から数値をランダムに 1 つ選ぶ
const random_index = Math.floor(Math.random() * nums.length);
// ランダムな要素を取得して返す
// ランダムに選んだ要素を取得して返す
const random_num = nums[random_index];
return random_num;
}
/* 配列長を拡張する */
// JavaScript の Array は動的配列であり、直接拡張できます
// 学習しやすいよう、本関数では Array を長さ不変の配列として扱います
/* 配列の長さを拡張する */
// JavaScript の Array は動的配列なので、そのまま拡張できることに注意
// 学習しやすいように、この関数では Array を長さが変わらない配列として扱う
function extend(nums, enlarge) {
// 拡張後の長さを持つ配列を初期化する
// 拡張後の長さの配列を初期化する
const res = new Array(nums.length + enlarge).fill(0);
// 元の配列の全要素を新しい配列にコピー
// 元の配列の全要素を新しい配列にコピーする
for (let i = 0; i < nums.length; i++) {
res[i] = nums[i];
}
@@ -27,38 +27,38 @@ function extend(nums, enlarge) {
return res;
}
/* 配列の index 番目に要素 num を挿入 */
/* 配列のインデックス index に要素 num を挿入する */
function insert(nums, num, index) {
// インデックス index 以降の全要素を 1 つ後ろへ移動する
// インデックス index 以降の全要素を 1 つ後ろにずらす
for (let i = nums.length - 1; i > index; i--) {
nums[i] = nums[i - 1];
}
// index の要素に num を代入する
// インデックス index の要素に num を代入する
nums[index] = num;
}
/* index の要素を削除する */
/* インデックス index の要素を削除する */
function remove(nums, index) {
// インデックス index より後ろの全要素を 1 つ前へ移動する
// インデックス index より後の全要素を 1 つ前にずらす
for (let i = index; i < nums.length - 1; i++) {
nums[i] = nums[i + 1];
}
}
/* 配列を走査 */
/* 配列を走査する */
function traverse(nums) {
let count = 0;
// インデックスで配列を走査
// インデックスを使って配列を走査する
for (let i = 0; i < nums.length; i++) {
count += nums[i];
}
// 配列要素を直接走査
// 配列の要素を直接走査する
for (const num of nums) {
count += num;
}
}
/* 配列内で指定要素を探す */
/* 配列から指定した要素を探索する */
function find(nums, target) {
for (let i = 0; i < nums.length; i++) {
if (nums[i] === target) return i;
@@ -66,8 +66,8 @@ function find(nums, target) {
return -1;
}
/* Driver Code */
/* 配列を初期化 */
/* 実行用コード */
/* 配列を初期化する */
const arr = new Array(5).fill(0);
console.log('配列 arr =', arr);
let nums = [1, 3, 2, 5, 4];
@@ -75,23 +75,23 @@ console.log('配列 nums =', nums);
/* ランダムアクセス */
let random_num = randomAccess(nums);
console.log('nums からランダム要素を取得', random_num);
console.log('nums からランダムに取得した要素', random_num);
/* 長さを拡張 */
/* 長さの拡張 */
nums = extend(nums, 3);
console.log('配列の長さを 8 に拡張し,nums =', nums);
console.log('配列の長さを 8 に拡張した結果 nums =', nums);
/* 要素を挿入する */
insert(nums, 6, 3);
console.log('インデックス 3 に数字 6 を挿入し,nums =', nums);
console.log('インデックス 3 に数値 6 を挿入した結果 nums =', nums);
/* 要素を削除 */
/* 要素を削除する */
remove(nums, 2);
console.log('インデックス 2 の要素を削除し,nums =', nums);
console.log('インデックス 2 の要素を削除した結果 nums =', nums);
/* 配列を走査 */
/* 配列を走査する */
traverse(nums);
/* 要素を探索する */
let index = find(nums, 3);
console.log('nums 内で要素 3 を検索し,インデックス =', index);
console.log('nums から要素 3 を探索した結果のインデックス =', index);
@@ -7,14 +7,14 @@
const { printLinkedList } = require('../modules/PrintUtil');
const { ListNode } = require('../modules/ListNode');
/* 連結リストでノード n0 の後ろにノード P を挿入する */
/* 連結リストのノード n0 の直後にノード P を挿入する */
function insert(n0, P) {
const n1 = n0.next;
P.next = n1;
n0.next = P;
}
/* 連結リストでノード n0 の直後のノードを削除する */
/* 連結リストのノード n0 の直後のノードを削除する */
function remove(n0) {
if (!n0.next) return;
// n0 -> P -> n1
@@ -23,7 +23,7 @@ function remove(n0) {
n0.next = n1;
}
/* 連結リスト内で index 番目のノードにアクセス */
/* 連結リストのインデックス index にあるノードにアクセスする */
function access(head, index) {
for (let i = 0; i < index; i++) {
if (!head) {
@@ -34,7 +34,7 @@ function access(head, index) {
return head;
}
/* 連結リストで値が target の最初のノードを探す */
/* 連結リストから値が target である最初のノードを探索する */
function find(head, target) {
let index = 0;
while (head !== null) {
@@ -47,36 +47,36 @@ function find(head, target) {
return -1;
}
/* Driver Code */
/* 連結リストを初期化 */
// 各ノードを初期化
/* 実行用コード */
/* 連結リストを初期化する */
// 各ノードを初期化する
const n0 = new ListNode(1);
const n1 = new ListNode(3);
const n2 = new ListNode(2);
const n3 = new ListNode(5);
const n4 = new ListNode(4);
// ノード間の参照を構築する
// ノード間の参照を設定する
n0.next = n1;
n1.next = n2;
n2.next = n3;
n3.next = n4;
console.log('初期化された連結リストは');
console.log('初期化した連結リスト');
printLinkedList(n0);
/* ノードを挿入 */
/* ノードを挿入する */
insert(n0, new ListNode(0));
console.log('ノード挿入後の連結リストは');
console.log('ノードを挿入した後の連結リスト');
printLinkedList(n0);
/* ノードを削除 */
/* ノードを削除する */
remove(n0);
console.log('ノード削除後の連結リストは');
console.log('ノードを削除した後の連結リスト');
printLinkedList(n0);
/* ノードにアクセス */
/* ノードにアクセスする */
const node = access(n0, 3);
console.log('連結リストのインデックス 3 のノードの値 = ' + node.val);
console.log('連結リストのインデックス 3 にあるノードの値 = ' + node.val);
/* ノードを探索 */
/* ノードを探索する */
const index = find(n0, 2);
console.log('連結リスト内で値が 2 のノードのインデックス = ' + index);
console.log('連結リスト内で値が 2 であるノードのインデックス = ' + index);
@@ -4,44 +4,44 @@
* Author: Justin ([email protected])
*/
/* リストを初期化 */
/* リストを初期化する */
const nums = [1, 3, 2, 5, 4];
console.log(`リスト nums = ${nums}`);
/* 要素にアクセス */
/* 要素にアクセスする */
const num = nums[1];
console.log(`インデックス 1 の要素にアクセスし,num = ${num}`);
console.log(`インデックス 1 の要素にアクセスした結果 num = ${num}`);
/* 要素を更新 */
/* 要素を更新する */
nums[1] = 0;
console.log(`インデックス 1 の要素を 0 に更新し,nums = ${nums}`);
console.log(`インデックス 1 の要素を 0 に更新した結果 nums = ${nums}`);
/* リストを空にする */
nums.length = 0;
console.log(`リストを空にした後,nums = ${nums}`);
console.log(`リストを空にした後 nums = ${nums}`);
/* 末尾に要素を追加 */
/* 末尾に要素を追加する */
nums.push(1);
nums.push(3);
nums.push(2);
nums.push(5);
nums.push(4);
console.log(`要素追加後,nums = ${nums}`);
console.log(`要素を追加した後 nums = ${nums}`);
/* 中間に要素を挿入 */
/* 途中に要素を挿入する */
nums.splice(3, 0, 6);
console.log(`インデックス 3 に数字 6 を挿入し,nums = ${nums}`);
console.log(`インデックス 3 に数値 6 を挿入した結果 nums = ${nums}`);
/* 要素を削除 */
/* 要素を削除する */
nums.splice(3, 1);
console.log(`インデックス 3 の要素を削除し,nums = ${nums}`);
console.log(`インデックス 3 の要素を削除した結果 nums = ${nums}`);
/* インデックスでリストを走査 */
/* インデックスを使ってリストを走査する */
let count = 0;
for (let i = 0; i < nums.length; i++) {
count += nums[i];
}
/* リスト要素を直接走査 */
/* リストの要素を直接走査する */
count = 0;
for (const x of nums) {
count += x;
@@ -50,8 +50,8 @@ for (const x of nums) {
/* 2 つのリストを連結する */
const nums1 = [6, 8, 7, 10, 9];
nums.push(...nums1);
console.log(`リスト nums1 を nums の後ろに連結し,nums = ${nums}`);
console.log(`リスト nums の後ろに nums1 を連結した結果 nums = ${nums}`);
/* リストをソート */
/* リストをソートする */
nums.sort((a, b) => a - b);
console.log(`リストをソート後,nums = ${nums}`);
console.log(`リストをソートした後 nums = ${nums}`);
@@ -6,42 +6,42 @@
/* リストクラス */
class MyList {
#arr = new Array(); // 配列(リスト要素を格納)
#capacity = 10; // リスト容量
#arr = new Array(); // 配列(リストの要素を格納する)
#capacity = 10; // リストの容量
#size = 0; // リストの長さ(現在の要素数)
#extendRatio = 2; // リスト拡張時の増加倍率
#extendRatio = 2; // リストの容量を拡張する際の倍率
/* コンストラクタ */
constructor() {
this.#arr = new Array(this.#capacity);
}
/* リストの長さを取得(現在の要素数) */
/* リストの長さ(現在の要素数)を取得する*/
size() {
return this.#size;
}
/* リスト容量を取得する */
/* リストの容量を取得する */
capacity() {
return this.#capacity;
}
/* 要素にアクセス */
/* 要素にアクセスする */
get(index) {
// インデックスが範囲外なら例外を送出する。以下同様
// インデックスが範囲外の場合、例外を送出する。以下も同様
if (index < 0 || index >= this.#size) throw new Error('インデックスが範囲外です');
return this.#arr[index];
}
/* 要素を更新 */
/* 要素を更新する */
set(index, num) {
if (index < 0 || index >= this.#size) throw new Error('インデックスが範囲外です');
this.#arr[index] = num;
}
/* 末尾に要素を追加 */
/* 末尾に要素を追加する */
add(num) {
// 長さが容量に等しい場合は拡張が必要
// 長さが容量に等しい場合、容量を拡張する必要がある
if (this.#size === this.#capacity) {
this.extendCapacity();
}
@@ -50,50 +50,50 @@ class MyList {
this.#size++;
}
/* 中間に要素を挿入 */
/* 途中に要素を挿入する */
insert(index, num) {
if (index < 0 || index >= this.#size) throw new Error('インデックスが範囲外です');
// 要素数が容量を超えると、拡張機構が発動する
// 要素数が容量を超える場合、容量を拡張する
if (this.#size === this.#capacity) {
this.extendCapacity();
}
// index 以降の要素をすべて 1 つ後ろへずらす
// インデックス index 以降の全要素を後ろに 1 つずらす
for (let j = this.#size - 1; j >= index; j--) {
this.#arr[j + 1] = this.#arr[j];
}
// 要素数を更新
// 要素数を更新する
this.#arr[index] = num;
this.#size++;
}
/* 要素を削除 */
/* 要素を削除する */
remove(index) {
if (index < 0 || index >= this.#size) throw new Error('インデックスが範囲外です');
let num = this.#arr[index];
// インデックス index より後の要素をすべて 1 つ前に移動する
// インデックス index より後の全要素を前に 1 つずらす
for (let j = index; j < this.#size - 1; j++) {
this.#arr[j] = this.#arr[j + 1];
}
// 要素数を更新
// 要素数を更新する
this.#size--;
// 削除された要素を返す
// 削除した要素を返す
return num;
}
/* リストの拡張 */
/* リストの容量を拡張する */
extendCapacity() {
// 元の配列の extendRatio 倍の長さを持つ新しい配列を作成し、元の配列をコピーする
// 元の配列の extendRatio 倍の長さの配列を新たに作成し、元の配列をコピーする
this.#arr = this.#arr.concat(
new Array(this.capacity() * (this.#extendRatio - 1))
);
// リストの容量を更新
// リストの容量を更新する
this.#capacity = this.#arr.length;
}
/* リストを配列に変換する */
toArray() {
let size = this.size();
// 有効長の範囲内のリスト要素のみを変換
// 有効な長さの範囲内にあるリストの要素だけを変換する
const arr = new Array(size);
for (let i = 0; i < size; i++) {
arr[i] = this.get(i);
@@ -102,40 +102,40 @@ class MyList {
}
}
/* Driver Code */
/* リストを初期化 */
/* 実行用コード */
/* リストを初期化する */
const nums = new MyList();
/* 末尾に要素を追加 */
/* 末尾に要素を追加する */
nums.add(1);
nums.add(3);
nums.add(2);
nums.add(5);
nums.add(4);
console.log(
`リスト nums = ${nums.toArray()} ,容量 = ${nums.capacity()} ,長さ = ${nums.size()}`
`リスト nums = ${nums.toArray()} 、容量 = ${nums.capacity()} 、長さ = ${nums.size()}`
);
/* 中間に要素を挿入 */
/* 途中に要素を挿入する */
nums.insert(3, 6);
console.log(`インデックス 3 に数字 6 を挿入し,nums = ${nums.toArray()}`);
console.log(`インデックス 3 に数値 6 を挿入した結果 nums = ${nums.toArray()}`);
/* 要素を削除 */
/* 要素を削除する */
nums.remove(3);
console.log(`インデックス 3 の要素を削除し,nums = ${nums.toArray()}`);
console.log(`インデックス 3 の要素を削除した結果 nums = ${nums.toArray()}`);
/* 要素にアクセス */
/* 要素にアクセスする */
const num = nums.get(1);
console.log(`インデックス 1 の要素にアクセスし,num = ${num}`);
console.log(`インデックス 1 の要素にアクセスした結果 num = ${num}`);
/* 要素を更新 */
/* 要素を更新する */
nums.set(1, 0);
console.log(`インデックス 1 の要素を 0 に更新し,nums = ${nums.toArray()}`);
console.log(`インデックス 1 の要素を 0 に更新した結果 nums = ${nums.toArray()}`);
/* 拡張機構をテストする */
/* 容量の拡張をテストする */
for (let i = 0; i < 10; i++) {
// i = 5 のとき、リスト長が容量を超えるため、この時点で拡張機構が発動する
// i = 5 のときにリストの長さが容量を超えるため、容量が拡張される
nums.add(i);
}
console.log(
`拡張後のリスト nums = ${nums.toArray()} ,容量 = ${nums.capacity()} ,長さ = ${nums.size()}`
`容量を拡張した後のリスト nums = ${nums.toArray()} 、容量 = ${nums.capacity()} 、長さ = ${nums.size()}`
);