Skip to content

Commit 390c008

Browse files
committed
変数名変更
1 parent f0ae2c0 commit 390c008

File tree

1 file changed

+10
-11
lines changed
  • docs/6-exercise/1-basis-of-web/_samples/bubble-sort/pure

1 file changed

+10
-11
lines changed

docs/6-exercise/1-basis-of-web/_samples/bubble-sort/pure/script.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
//第一引数の配列の第二引数、第三引数のインデックスの要素を入れ替える関数
2-
function swapIndex(array, indexA, indexB) {
3-
const arrayToChange = array.slice(); //配列の各値をコピー
4-
const temp = arrayToChange[indexA];
5-
arrayToChange[indexA] = arrayToChange[indexB];
6-
arrayToChange[indexB] = temp;
7-
return arrayToChange;
2+
function swapIndex(inputArray, indexA, indexB) {
3+
const newArray = inputArray.slice(); //配列の各値をコピー
4+
const temp = newArray[indexA];
5+
newArray[indexA] = newArray[indexB];
6+
newArray[indexB] = temp;
7+
return newArray;
88
}
99

1010
//本関数
11-
function bubbleSort(array) {
12-
let willResult = array.slice(); // 配列の各値をコピー
11+
function bubbleSort(inputArray) {
12+
let array = inputArray.slice(); // 配列の値をコピー
1313
for (let i = array.length - 1; i > 0; i--) {
1414
for (let j = 0; j < i; j++) {
15-
if (willResult[j] > willResult[j + 1])
16-
willResult = swapIndex(willResult, j, j + 1);
15+
if (array[j] > array[j + 1]) swapIndex(array, j, j + 1);
1716
}
1817
}
19-
return willResult;
18+
return array;
2019
}
2120

2221
let unsortedArray = [9, 3, 1, 5, 8, 2, 4, 7, 6, 10];

0 commit comments

Comments
 (0)