# Insert Sort

Compare each element of the unordered array (original array) to each element of the ordered array. The first element of the original array is counted as the first element of the ordered array (notice that the outside loop starts from the second element, index 1). The ordered array is sorted in ascending order from the left when the compared number in the unordered array that is smaller than the elements of the unordered array is kept pushed to the left.

```
var list = [4, 2, 1, 3, 5, 10, 30, 5, 8];
for ( var i=1, len=list.length; i<len; i++) {
for (var j=i; j > 0; j--) {
if (list[j-1] > list[j]) {
var c = list[j];
list[j] = list[j-1];
list[j-1] = c;
}
}
}
// result [ 1, 2, 3, 4, 5, 5, 8, 10, 30 ]
```