Created
October 24, 2021 09:37
-
-
Save mustafadalga/3b22bd8e7d96a14a8f2927952e93f100 to your computer and use it in GitHub Desktop.
Insertion Sort Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insertionSort(array) { | |
let adım = 1; | |
for (let i = 1; i < array.length; i++) { | |
var currentValue = array[i] | |
for (var j = i - 1; j >= 0 && array[j] > currentValue; j--) { | |
array[j + 1] = array[j]; | |
} | |
array[j + 1] = currentValue | |
adım++; | |
} | |
return array; | |
} | |
const numberList=[...new Set(Array.from({length: 50}, () => Math.floor(Math.random() * 250)))]; | |
console.log(insertionSort(numberList)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment