Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lesyk committed Feb 28, 2021
1 parent e259130 commit 91ad178
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Algorithms/Sorting/InsertionSort/InsertionSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,19 @@ function insertionSort(numbers: number[]): number[] {
return sortedNumbers;
}

function insertionSort2(arr: number[]): number[] {
for (let i = 1; i < arr.length; i++) {
for (let sortedJ = 0; sortedJ <= i; sortedJ++) {
if (arr[i] < arr[sortedJ]) {
const t = arr[i];
arr.splice(i, 1);
arr.splice(sortedJ, 0, t);
}
}
}

return arr;
}

const unsortedArrayToSort = [5, 15, 14, 1, 26, 0, 99];
console.log(insertionSort(unsortedArrayToSort));

0 comments on commit 91ad178

Please sign in to comment.