Skip to content

Instantly share code, notes, and snippets.

@eengineergz
Created February 27, 2021 05:22
Show Gist options
  • Save eengineergz/ffead1de0836c4bcc6445780a604f617 to your computer and use it in GitHub Desktop.
Save eengineergz/ffead1de0836c4bcc6445780a604f617 to your computer and use it in GitHub Desktop.
let insertionSort = (inputArr) => {
let length = inputArr.length;
for (let i = 1; i < length; i++) {
let key = inputArr[i];
let j = i - 1;
while (j >= 0 && inputArr[j] > key) {
inputArr[j + 1] = inputArr[j];
j = j - 1;
}
inputArr[j + 1] = key;
}
return inputArr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment