style(InsertionSort.js): Changed var to let (scope taken into account)

This commit is contained in:
Rak Laptudirm
2021-05-21 11:52:37 +05:30
parent b702faadc5
commit 8b7c5fdc57

View File

@ -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]
} }