mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
style: Fixed most styles (according to standardjs)
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
* the correct position and expand sorted part one element at a time.
|
||||
*/
|
||||
function insertionSort (unsortedList) {
|
||||
var len = unsortedList.length
|
||||
for (var i = 1; i < len; i++) {
|
||||
var tmp = unsortedList[i] // Copy of the current element.
|
||||
const len = unsortedList.length
|
||||
for (let i = 1; i < len; i++) {
|
||||
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 */
|
||||
for (var j = i - 1; j >= 0 && (unsortedList[j] > tmp); j--) {
|
||||
// Shift the number
|
||||
@@ -19,6 +19,6 @@ function insertionSort (unsortedList) {
|
||||
}
|
||||
}
|
||||
|
||||
var arr = [5, 3, 1, 2, 4, 8, 3, 8]
|
||||
const arr = [5, 3, 1, 2, 4, 8, 3, 8]
|
||||
insertionSort(arr)
|
||||
console.log(arr)
|
||||
|
||||
Reference in New Issue
Block a user