Skip to content

1、大佬这里的 over 需要 over > 0 吧? #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xllpiupiu opened this issue Oct 1, 2021 · 0 comments
Closed

1、大佬这里的 over 需要 over > 0 吧? #167

xllpiupiu opened this issue Oct 1, 2021 · 0 comments

Comments

@xllpiupiu
Copy link

1、大佬这里的 over 需要 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 #138 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant