Skip to content

Commit a9e6c17

Browse files
authored
Update 3.insertionSort.md
fixed: js bug
1 parent b62c681 commit a9e6c17

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

3.insertionSort.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
function insertionSort(arr) {
2424
var preIndex;
2525
for (var i = 1; i < arr.length; i++) {
26+
var current = arr[i];
2627
preIndex = i - 1;
2728
while(preIndex >= 0 && arr[preIndex] > arr[i]) {
2829
arr[preIndex + 1] = arr[preIndex];
2930
preIndex--;
3031
}
31-
arr[preIndex + 1] = arr[i];
32+
arr[preIndex + 1] = current;
3233
}
3334
return arr;
3435
}

0 commit comments

Comments
 (0)