//This function used to add Sorted element in new array with ascending order
function swapElement(arr,xl,yl){
var temp = arr[xl];
arr[xl] = arr[yl];
arr[yl]=temp;
}
function sortArray(arr,n){
var i,j,min_idx;
//first loop for pic one element to check
for(let i=0;i<n-1;i++){
min_idx=i;
//this loop to check the i element is smaller or larger then other
for(let j=i+1;j<n;j++){
if(arr[j] < arr[min_idx]){
min_idx=j;
}
swapElement(arr,min_idx,i);
}
}
}
function printArray(arr,n){
for(let i=0;i<n;i++){
console.log(arr[i].toString());
}
}
var array = [12,0,13,-1,18,2];
var n = 6;
sortArray(array,n);
console.log('Sorted Array is : ')
printArray(array,n);
//Point to note
// Time Complexity is O(N`2`)
To embed this project on your website, copy the following code and paste it into your website's HTML: