Skip to content

Instantly share code, notes, and snippets.

@educartoons
Created June 23, 2020 22:52
Show Gist options
  • Save educartoons/f71b19365e623d636222160015e8c3a5 to your computer and use it in GitHub Desktop.
Save educartoons/f71b19365e623d636222160015e8c3a5 to your computer and use it in GitHub Desktop.
Implementation of Insertion Sort in Typescript
function insertionSort(A: number[]): number[] {
for (let j = 1; j < A.length; j++) {
let key = A[j];
let i = j - 1;
while (i >= 0 && A[i] > key) {
A[i + 1] = A[i];
i = i - 1;
}
A[i + 1] = key;
}
return A;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment