function insertionSort(arr){
for(i=0;i<arr.length;i++){
console.log(`*********`);
for(j=i+1;j<arr.length;j++){
if(arr[i]>arr[j]){
var temp =0;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
console.log(arr);
}
}
}
return arr
}
console.log(insertionSort([22,1,19,76,4]));
function selectionSort(arr){
const swap = (arr,idx1,indx2) =>
([arr[idx1], arr[idx2]] = [arr[idx2], arr[idx1]]);
for (let i = 0 ; i< arr.length; i++){
let lowest = i;
for (let j = i+1; j< arr.length; j++){
if(arr[lowest] > arr[j]){
lowest = j;
}
}
if(i !== lowest) swap(arr,i,lowest);
}
return arr;
}
console.log(selectionSort([0,2,34,22,10,19,17]));
function bb(arr){
for (var i = arr.length ; i>0 ; i--){
var noswap;
for(var j = 0; j < i-1; j++){
if(arr[j] > arr[j+1]){
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
noswap = false;
}
}
if(noswap) break;
}
return arr
}
console.log(bb([1,29,3,44,5]));