JSFiddle - React, Tailwind, and code Playground
JavaScript
Array.prototype.insert_sort=function(){
var key;
var t;
for (j=1;j<this.length ;j++ )//從陣列第二個元素開始迴圈。
{
key=this[j];
t=j-1;
while (t>=0 && this[t]>key)
{
this[t+1]=this[t];
this[t]=key;//如果迴圈到的元素比其前一個元素大,則互換其位置。
t--;
}
}
return this;
}