插入排序
js
Array.prototype.insertionSort = function () {
const arr = this;
let pre, curVal;
for (let i = 1; i < arr.length; i++) {
pre = i - 1;
curVal = arr[i];
while (pre >= 0 && arr[pre] > curVal) {
arr[pre + 1] = arr[pre];
pre--;
}
arr[pre + 1] = curVal;
}
console.log(arr);
};