Skip to content

Instantly share code, notes, and snippets.

@mustafadalga
Created October 24, 2021 09:37
Show Gist options
  • Save mustafadalga/3b22bd8e7d96a14a8f2927952e93f100 to your computer and use it in GitHub Desktop.
Save mustafadalga/3b22bd8e7d96a14a8f2927952e93f100 to your computer and use it in GitHub Desktop.
Insertion Sort Algorithm
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