mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
style(InsertionSort.js): Changed var to let (scope taken into account)
This commit is contained in:
@ -7,9 +7,10 @@
|
|||||||
function insertionSort (unsortedList) {
|
function insertionSort (unsortedList) {
|
||||||
const len = unsortedList.length
|
const len = unsortedList.length
|
||||||
for (let i = 1; i < len; i++) {
|
for (let i = 1; i < len; i++) {
|
||||||
|
let j
|
||||||
const tmp = unsortedList[i] // Copy of the current element.
|
const tmp = unsortedList[i] // Copy of the current element.
|
||||||
/* Check through the sorted part and compare with the number in tmp. If large, shift the number */
|
/* Check through the sorted part and compare with the number in tmp. If large, shift the number */
|
||||||
for (var j = i - 1; j >= 0 && (unsortedList[j] > tmp); j--) {
|
for (j = i - 1; j >= 0 && (unsortedList[j] > tmp); j--) {
|
||||||
// Shift the number
|
// Shift the number
|
||||||
unsortedList[j + 1] = unsortedList[j]
|
unsortedList[j + 1] = unsortedList[j]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user