Closed xllpiupiu closed 2 years ago
1、大佬这里的 over 需要 over > 0 吧?
over > 0
let over = addCount - delCount; if(over) { // 向后移
2、这块的逻辑处理好像不太对(稀疏数组也存在类似情况)。
} else if (over < 0) { // 向前移 for(let i = startIndex + delCount; i <= array.length - 1; i++) { if(i + Math.abs(over) > array.length - 1) { // 删除冗于元素 delete array[i] continue } array[i] = array[i + Math.abs(over)] } } }
例如:
var arr = [1,2,3,4,5]; arr.splice(0, 3, 6, 7); console.log(arr); // - 预期结果:[6, 7, 4, 5] - 实际结果:[6, 7, 3, 5]
Originally posted by @MeetTheBest in https://github.com/sisterAn/JavaScript-Algorithms/issues/138#issuecomment-846373010
1、大佬这里的 over 需要
over > 0
吧?2、这块的逻辑处理好像不太对(稀疏数组也存在类似情况)。
例如:
Originally posted by @MeetTheBest in https://github.com/sisterAn/JavaScript-Algorithms/issues/138#issuecomment-846373010