Skip to content

Commit 721bad0

Browse files
committed
No frills implementation of Insertion sort.
1 parent dba0a2d commit 721bad0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var insertionSort = function(unsorted){
2+
for(var i=0;i<unsorted.length;i++){
3+
var temp = unsorted[i];
4+
j=i-1;
5+
while((j>=0)&&(unsorted[j]>temp)){
6+
unsorted[j+1]=unsorted[j];
7+
j--;
8+
}
9+
unsorted[j+1] = temp;
10+
}
11+
12+
return unsorted;
13+
}
14+
15+
console.log(insertionSort([2,5,7,4,8,10]));

0 commit comments

Comments
 (0)