DEV Community

Riaj Ahmed
Riaj Ahmed

Posted on

What kind of sorting method it is?

let arr=[57,2,3,12,43,23,23,43,56,98,03,77,23]
let insertion= a=>{
if(a.length<2){return a}
for(var i=0; i<a.length; i++){
//console.log(" value of i=",i, "move to ", a[i])
let temp
if(a[i]<a[i+1]){
//console.log( a[i], a[i+1])
temp=a[i]
a[i]=a[i+1]
a[i+1]=temp
i=i-2
}//else{console.log("nothing to do")}
}
return arr
}
console.log(insertion(arr))

Top comments (0)