插入排序
将数组分为已排序和待排序数组,每次从待排序数组中拿出最前面的数插入到已排序的数组中
function insertSort(arr){if(!arr || arr.length <= 0){return [];}let len = arr.length;for(let i = 1; i < len; i++){let pre = i - 1;let curr = arr[i];while (pre >= 0 && arr[pre] > curr) {arr[pre + 1] = arr[pre];pre--;}arr[pre + 1] = curr;}return arr;
}