Skip to content

Commit a314e1f

Browse files
committed
add insertion sort algo
1 parent 23e37bd commit a314e1f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function insertionSort(arr: Array<number>): Array<number> {
2+
for(let i = 0; i < arr.length - 1; i++){
3+
let lowestInd = i;
4+
//let lowestVal = arr[i];
5+
for (let j = i + 1; j < arr.length; j++){
6+
if(arr[j] < arr[lowestInd]){
7+
lowestInd = j;
8+
}
9+
}
10+
let temp = arr[i];
11+
arr[i] = arr[lowestInd];
12+
arr[lowestInd] = temp;
13+
}
14+
15+
return arr;
16+
}

0 commit comments

Comments
 (0)