function InsertionSort(arr,n){
    let i,j,key;
    for(i=1;i<n;i++){
        key = arr[i];
        j=i-1;
        //traverse key with remaining element of the array 
        //and swap with one position ahed
        while(j>=0 && arr[j]>key){
            arr[j+1]=arr[j];
            j=j-1;
        }
        arr[j+1]=key;
    }
}

function printArray(arr,n){
    for(let i=0;i<n;i++){
        console.log(arr[i],'');
    }
}

let array = [11,24,3,75,8,0,12];
let n = array.length;

InsertionSort(array,n);
printArray(array,n);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: