-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
第 158 题:如何模拟实现 Array.prototype.splice #384
Comments
Array.prototype._splice = function (start, deleteCount, ...addList) {
if (start < 0) {
if (Math.abs(start) > this.length) {
start = 0
} else {
start += this.length
}
}
if (typeof deleteCount === 'undefined') {
deleteCount = this.length - start
}
const removeList = this.slice(start, start + deleteCount)
const right = this.slice(start + deleteCount)
let addIndex = start
addList.concat(right).forEach(item => {
this[addIndex] = item
addIndex++
})
this.length = addIndex
return removeList
} |
|
This comment has been minimized.
This comment has been minimized.
Array.prototype.mySplice = function (start, count, ...args) { |
// splice
let arr1 = [1, 3, 5, 7, 9];
let arr2 = [1, 3, 5, 7, 9];
/*
一个参数表示删除后面所有元素
两个参数表示走a开始删b个元素
两个以上表示走a开始删b个元素,再这个位置添加元素
*/
Array.prototype.mySplice = function (index, delCount, ...args) {
// 判断this
if (this === null || this === undefined) {
throw new TypeError(
"Cannot read property 'map' of null or undefined"
);
}
let O = Object(this),
len = O.length;
// 第一个参数,不存在 (返回空数组)
if (index === undefined) {
return [];
}
index = Number(index);
// 第一个参数不是数字 (全删除)
if (isNaN(index)) {
return delArray(O, 0);
}
// index若为负值或者超过length
index = changeIndex(index, len);
// 第二个参数没有 (后面的全删除)
if (delCount === undefined) {
return delArray(O, index);
}
// 第二个参数不是数字 (返回空数组)
if (isNaN(delCount)) {
return [];
} else {
// 第三个参数存在
if (Array.isArray(args)) {
return add(O, index, delCount, args);
}
// 不存在
// 删除数组
return delArray(O, index, delCount);
}
};
function changeIndex(index, len) {
// 若为负值
while (index < 0) {
index += len;
}
// 若为超过len的值
if (index >= len) {
index = len;
}
return index;
}
// 添加元素
function add(arr, index, count, temp) {
// 先删除
let a = delArray(arr, index, count);
// 添加元素
for (let i = 0; i < temp.length; i++) {
// 外层循环添加次数
for (let j = arr.length; j > index + i; j--) {
arr[j] = arr[j - 1];
}
arr[index + i] = temp[i];
}
return a;
}
// 删除元素
function delArray(arr, index, count = arr.length) {
let temp = [],
len = arr.length;
//判断有效的count
count = len - index >= count ? count : len - index;
for (let i = 0; i < count; i++) {
let item = arr[index + i];
temp.push(item);
}
while (count) {
count--;
for (let j = index; j < arr.length - 1; j++) {
arr[j] = arr[j + 1];
}
let len_ = arr.length - 1;
delete arr[len_];
arr.length = len_;
}
return temp;
}
let res1 = arr1.mySplice(1, 1, 111, 222, 333);
let res2 = arr2.splice(1, 1, 111, 222, 333);
console.log(res1, arr1, res2, arr2); |
前端的原始API还有没写的吗? |
Array.prototype.splice = function (start, deleteCount, ...args) {
// 处理start值
if (start < 0) {
if (Math.abs(start) > this.length - 1) {
start = 0
} else {
start += this.length
}
}
// 处理deleteCount值
deleteCount = typeof deleteCount !== 'undefined' ? deleteCount : this.length
// 处理args值
args = args.length ? args : []
// 处理特殊情况
if (start > this.length - 1) {
this.concat(args)
return []
}
/**
* 思路
* 先把原数组值取出,原数组清空
* 先入栈不需要处理的数组前部分元素
* 然后把需要加入的args
* 最后入栈数组后部分元素
* 返回中间删掉的元素组成的数组
*/
let arr = [...this]
this.length = 0 // 清空
// 先入栈前部分元素
let i = 0
while (i < start) {
this.push(arr.shift())
i++
}
// 入栈args
args.forEach(item => this.push(item))
// 入栈后部分元素
arr.forEach((item, index) => {
if (index >= deleteCount) {
this.push(item)
delete arr[index]
}
})
// 返回删除部分
return arr
} |
//@ts-ignore
Array.prototype._splice = function (index: number, count: number, ...args: any[]) {
const deletes = [];
let res = [];
let pushIndex;
for(let i = 0; i < this.length; i++){
if(i === index && args.length){
pushIndex = i;
}
if(i >= index && i < (index+count)){
deletes.push(this[i]);
continue;
}
res.push(this[i]);
}
if(pushIndex !== void 0){
const left = res.slice(0, pushIndex);
const right = res.slice(pushIndex, res.length);
res = [...left, ...args, ...right];
}
this.length = 0;
this.push(...res);
return deletes;
} |
Array.prototype.spliceMy = function (startIndex, endIndex, ...item) {
if (startIndex < 0) {
startIndex = this.length + startIndex
endIndex = this.length + startIndex + endIndex
} else {
endIndex = startIndex + endIndex
}
let arrStart = this.slice(0, startIndex)
let arrEnd = this.slice(endIndex, this.length)
console.log(arrStart, arrEnd)
let returnArr = this.slice(startIndex, endIndex)
let newArr = arrStart.concat(item).concat(arrEnd)
for (let i = 0; i < newArr.length; i++) {
this[i] = newArr[i];
}
this.length = newArr.length
return returnArr
} |
/**
* @param {number} idx 开始删除的索引
* @param {number} deleteCount 需要删除的数目
* @param {any[]} insertItems 需要插入项
* @returns {any[]} 被删的数组项的数组
*/
Array.prototype.mySplice = function (idx, deleteCount) {
var arr = this;
var length = arr.length;
var insertItems = [].slice.call(arguments, 2);
deleteCount =
typeof deleteCount !== 'undefined' && deleteCount <= length - idx
? deleteCount
: length - idx;
var res = [];
while (deleteCount) {
deleteCount--;
if (idx in arr) {
res.push(arr[idx]);
}
for (var i = idx; i < arr.length - 1; i++) {
arr[i] = arr[i + 1];
}
arr.length = arr.length - 1;
}
for (var j = 0; j < insertItems.length; j++) {
arr.push(insertItems[j]);
}
return res;
}; 写了一个TS的,编译了下 |
有几点需要注意的: 1、第一个参数,开始下标 4、操作的都是原数组,也就是改变的是原数组 下边这个是我老早之前写的,参考了 chrome 的实现方式 Array.prototype._splice = function () {
if (arguments.length === 0) return [];
var arg_len = arguments.length,
array_len = this.length,
index = parseInt(arguments[0]) ? parseInt(arguments[0]) : 0,
num = parseInt(arguments[1])
? parseInt(arguments[1]) < 0
? 0
: parseInt(arguments[1])
: 0;
// 起始下标
if (index < 0) {
index += array_len;
if (index < 0) {
index = 0;
}
}
// 删除个数
if (index + num > array_len) {
num = array_len - index;
}
// 删除
var new_array = [];
if (num > 0) {
for (var i = 0, k = 0; i < array_len; i++) {
if (i !== index) {
this[k++] = this[i];
} else {
for (var j = 0; j < num; j++) {
new_array[j] = this[i++];
}
i--;
}
}
}
// 插入数据
this.length = array_len - num + (arg_len < 2 ? 0 : arg_len - 2);
if (arg_len === 2) {
return new_array;
}
array_len -= num;
for (i = this.length - 1; i >= 0; i--) {
if (i !== index + arg_len - 3) {
this[i] = this[--array_len];
} else {
for (j = arg_len - 1; j > 1; j--, i--) {
this[i] = arguments[j];
}
i++;
}
}
return new_array;
}; |
/***
|
(function () {
const del = (arr, index, len) => {
if (index < 0) {
index = arr.length - Math.abs(index);
}
let i = index + len;
let result = [];
let count = len;
let offset = index;
while (count--) {
result.push(arr[offset++]);
}
while (i < arr.length) {
arr[i - len] = arr[i];
i++;
}
arr.length = arr.length - len;
return result;
}
const insert = (arr, index, items) => {
// arr.length = arr.length + items.length;
let i = arr.length - 1;
while (i >= index) {
arr[i + items.length] = arr[i];
i--;
}
i = 0;
while (i < items.length) {
arr[i + index] = items[i];
i++
}
}
Array.prototype._splice = function _splice(index, deleteCount, ...rest) {
let arr = this;
let removed = [];
// 只有一个元素
if (deleteCount === undefined) {
removed = del(arr, index, arr.length - Math.abs(index));
} else {
removed = del(arr, index, deleteCount);
if (rest.length) {
insert(arr, index, rest);
}
}
return removed;
}
var myFish = ["angel", "clown", "mandarin", "sturgeon"];
var removed = myFish._splice(2, 0, "drum");
console.log(myFish, removed)
// 运算后的 myFish: ["angel", "clown", "drum", "mandarin", "sturgeon"]
// 被删除的元素: [], 没有元素被删除
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish._splice(2, 0, 'drum', 'guitar');
console.log(myFish, removed)
// 运算后的 myFish: ["angel", "clown", "drum", "guitar", "mandarin", "sturgeon"]
// 被删除的元素: [], 没有元素被删除
var myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon'];
var removed = myFish._splice(3, 1);
console.log(myFish, removed)
// 运算后的 myFish: ["angel", "clown", "drum", "sturgeon"]
// 被删除的元素: ["mandarin"]
var myFish = ['angel', 'clown', 'drum', 'sturgeon'];
var removed = myFish._splice(2, 1, "trumpet");
console.log(myFish, removed)
// 运算后的 myFish: ["angel", "clown", "trumpet", "sturgeon"]
// 被删除的元素: ["drum"]
var myFish = ['angel', 'clown', 'trumpet', 'sturgeon'];
var removed = myFish._splice(0, 2, 'parrot', 'anemone', 'blue');
console.log(myFish, removed)
// 运算后的 myFish: ["parrot", "anemone", "blue", "trumpet", "sturgeon"]
// 被删除的元素: ["angel", "clown"]
var myFish = ['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'];
var removed = myFish._splice(myFish.length - 3, 2);
console.log(myFish, removed)
// 运算后的 myFish: ["parrot", "anemone", "sturgeon"]
// 被删除的元素: ["blue", "trumpet"]
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish._splice(-2, 1);
console.log(myFish, removed)
// 运算后的 myFish: ["angel", "clown", "sturgeon"]
// 被删除的元素: ["mandarin"]
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish._splice(2);
console.log(myFish, removed)
// 运算后的 myFish: ["angel", "clown"]
// 被删除的元素: ["mandarin", "sturgeon"]
})() |
Array.prototype.splice = function(start, delCount, ...items) {
let arr = this
let delArr = []
let end = start
const len = arr.length
const startArr = arr.slice(0, start)
if (delCount && delCount > 0) {
end += delCount
delArr = delArr.concat(arr.slice(start, end))
}
const endArr = arr.slice(end, len+1)
const newArr = startArr.concat(items).concat(endArr)
newArr.forEach((item,index) => {
this[index] = item
})
this.length = newArr.length
return delArr
} |
Array.prototype.mySplice = function(start, deleteCount, ...items) {
const preLen = this.length + items.length
const rightArr = items.concat(this.slice(start + deleteCount))
let i = start
while(rightArr.length) {
this[i] = rightArr.shift()
i++
}
this.length = preLen - deleteCount
} |
最短代码数😝 |
各位大佬指点一下 Array.prototype.splice = function (index, howmany, ...items) {
items = items || []
var arr = this
var len = arr.length
var deleteItems = []
if (howmany == items.length) {
for (var i = index; i < index + howmany; i++) {
deleteItems.push(arr[i])
arr[i] = items[i - index]
}
} else if (howmany > items.length) {
var i = index
var temp = howmany
while (howmany) {
deleteItems.push(arr[i])
arr[i] = items[i - index]
i++
howmany--
}
for (var i = index + items.length; i < len; i++) {
arr[i] = arr[i + temp - items.length]
}
arr.length = len - (temp - items.length)
} else if (howmany < items.length) {
var step = items.length - howmany
var i = len + step - 1
while (i >= index) {
if (i < items.length + index) {
arr[i] = items[i - index]
} else {
arr[i] = arr[i - step]
}
i--
}
}
return deleteItems
}
var arr = [0, 1, 2, 3, 4, 5, 6]
arr.splice(3, 3, ...[7, 8, 9])
console.log(arr) |
大佬,你这个好像有点问题啊,这块就有点问题,第二个参数没有,应该从第一个参数开始往后删除,不应该直接全删除吧
|
|
/**
* Array.prototype.splice polyfill
* 时间复杂度: o(1n) 一次遍历
* 空间复杂度: o(1n) 原地算法
*/
Array.prototype.splice = function(start, deleteCount, ...items) {
if (typeof start !== 'number' || isNaN(start)) {
throw new TypeError('start must be a number');
}
if (start < 0) {
start = this.length - start;
}
if (deleteCount !== undefined &&
(typeof deleteCount !== 'number' || isNaN(deleteCount) )
) {
throw new TypeError('deleteCount must be a number');
}
if (deleteCount === undefined || deleteCount > this.length - start ) {
deleteCount = this.length - start;
}
const res = [];
// 计算移动方向, 不同的移动方向操作不同
// 左移: 从左往右遍历
// 右移: 从右往左移动
let moveVector = items.length - deleteCount,
// 待插入的元素个数
pendingIntert = items.length;
if (moveVector <= 0) {
for (let i = start; i < this.length; i++) {
// 记录删除的元素
if (i - start < deleteCount) {
res.push(this[i]);
}
if (i < this.length + moveVector) {
// 如果有未插入的元素, 先插入
if (pendingIntert > 0) {
this[i] = items[items.length - pendingIntert--];
} else {
// 如果没有未插入元素, 左移
this[i] = this[i - moveVector];
}
}
}
// 缩减数组长度
this.length = this.length + moveVector;
} else {
for (let i = this.length + moveVector - 1; i >= start; i--) {
// 记录删除的元素
if (i - start < deleteCount) {
res.unshift(this[i]);
}
if (i < start + items.length) {
// 开始插入元素
this[i] = items[--pendingIntert];
} else {
// 右移
this[i] = this[i - moveVector];
}
}
}
return res;
}
const testArr = [1, 2, 3];
console.log('res', testArr.splice(0, 1, 4, 5, 6, 7));
console.log(testArr); |
没有看到返回值 |
Array.prototype.splice2 = function(start, delCount, ...args) {
let firstPart = []
let secondPart = []
let res = []
start = start > 0 ? start : (this.length + start)
delCount = delCount || this.length - start
for (let i = 0; i < this.length; i++) {
if (i < start) {
firstPart.push(this[i])
} else {
secondPart.push(this[i])
}
}
for (let i = 0; i < delCount; i++) {
res.push(secondPart[i])
delete secondPart[i]
}
const newlist = firstPart.concat(args).concat(secondPart.filter(item => item))
newlist.forEach((item, index) => {
this[index] = item
})
this.length = newlist.length
return res
}
let arr1 = ['jk', 26, 'chrome', 'mac', 'win']
let arr2 = ['jk', 26, 'chrome', 'mac', 'win']
console.log(arr1.splice2(-2, 2), arr1)
console.log(arr2.splice(-2, 2), arr2) |
Array.prototype._splice = function (start, deleteCount, ...addList) {
|
Array.prototype.splice = function (start = 0, number = 0, value) {
const arr = [...this];
const delArr = [];
const range = start + number;
this.length = 0;
for (const [index, item] of arr.entries()) {
if (index > range) {
this.push(item);
} else if (index === range) {
if (value) {
this.push(value);
}
this.push(item);
} else {
if (index < start) {
this.push(item);
} else {
delArr.push(item);
}
}
}
return delArr;
}; |
|
思路: const arr = [1, 2, 12, 32, 43]
const after = arr.splice(-1, -2,33, 4);
console.log('答案 ---', arr, after);
const arr2 = [1, 2, 12, 32, 43];
function splice(list, start, deleteNum, ...addList) {
const startIndex = start > 0 ? start : list.length - Math.abs(start);
const endIndex = deleteNum > 0 ? startIndex + deleteNum : undefined;
let left = [];
let splice = [];
let right = [].concat(addList);
list.forEach((item, index) => {
if (index < startIndex) left.push(item);
if (index >= startIndex && endIndex === undefined) {
right.push(item);
return;
}
if (index >= startIndex && index < endIndex) splice.push(item);
if (index >= endIndex) right.push(item);
})
list.length = 0;
list.push(...left, ...right);
return splice;
}
const newArr = splice(arr2, -1, -2,33, 4);
console.log('结果 ---', arr2, newArr); |
大佬 您这个是真的秀了!!秀的我眼花缭乱 |
100% mock Array.prototype.spliceArray.prototype._splice = function(index, cutNum, ...args) {
const arr = this;
const leftArr = arguments.length === 0 ? [] : arr.slice(0, index);
const rightArr = arguments.length === 1 ? [] : arr.slice(index + (cutNum || 0));
const changeArr = [...leftArr, ...args, ...rightArr];
const result = arguments.length === 1 ? arr.slice(index) : arr.slice(index, index + cutNum)
changeArr.forEach((val,index) => this[index] = val); // change
this.length = changeArr.length;
return result;
} // test
var arr1 = [1,2,3,4,5,6,7];
var arr2 = [1,2,3,4,5,6,7];
console.log(arr1.splice(1,3,'a','b'));
console.log(arr1);
console.log(arr2._splice(1,3,'a','b'));
console.log(arr2); |
Array.prototype.splice = function (start, deleteCount, ...items) {
if (start < 0) {
start += this.length;
}
if (start < 0) start = 0;
if (deleteCount == undefined) {
deleteCount = this.length - start;
} else if (deleteCount < 0) {
deleteCount = 0;
}
const left = [].slice.call(this, 0, start);
const deleted = [].slice.call(this, start, start + deleteCount);
const right = [].slice.call(this, start + deleteCount);
this.length = 0;
this.push(...left, ...items, ...right);
return deleted;
}; |
|
Array.prototype.splice2 = function(start, count, ...addList) {
if (start < 0) {
if (Math.abs(start) > this.length) {
start = 0
} else {
start = this.length + start
}
}
if (typeof count !== 'number') {
count = this.length - start
} else {
if (count < 0) {
count = 0
}
}
let delList = this.slice(start, start + count)
let right = this.slice(start + count, this.length)
this.length = start
this.push(...(addList.concat(right)))
return delList
} |
Array.prototype.spliceLike = function(start, num, ...params) {
return [...this.slice(0, start), ...params, ...this.slice(start + num)]
} |
Array.prototype._splice = function (start, count, ...replaceEl) {
if (typeof start !== "number") throw new Error("start not a number");
if (typeof count !== "number") throw new Error("count not a number");
start = start < 0 ? Math.max(start + this.length, 0) : start; // 开始值为负数要加上数组长度且不能小于零;
Math.max(0, count); // 删除数量大于等于0;
const delArr = this.slice(start, start + count);
const resArr = [
...this.slice(0, start),
...replaceEl,
...this.slice(start + count),
];
delArr.forEach((item, index) => {
delete this[index];
});
resArr.forEach((item, index) => {
this[index] = item;
});
this.length = resArr.length;
return delArr;
}; |
const arr1 = [1, 2, 3, 4, 5]; |
sart 大于数组长度就不对了
start大于数组长度就不对了 |
Array.prototype.splice = function(index, num, ...rest) {
let context = this
let removeList = []
//index为负值
if (index < 0) {
index = index + context.length
}
//num存在
if(num != null) {
if (num !== 0) {
//查找要删除的元素
for (let i = index; i < index + num; i++) {
removeList.push(context[i])
}
//移除要移除的元素
const conLength = context.length
for (let i = index + num; i < conLength; i++) {
context[i - num] = context[i]
}
context.length = conLength - num
}
//添加要添加的元素
if (rest.length > 0) {
const restLength = rest.length
const conLength = context.length
for(let i = conLength - 1; i >= index; i--) {
context[i+restLength] = context[i]
}
let count = 0
for(let i = index; i < index+restLength; i++) {
context[i] = rest[count]
count++
}
}
} else {
//查找要删除的元素
const conLength = context.length
for (let i = index; i < conLength; i++) {
removeList.push(context[i])
}
context.length = index
}
return removeList
}
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish.splice(2, 0, 'drum', 'guitar');
console.log(myFish)
console.log(removed)
//应该把数组第index位左移或右移n位抽象成函数,看起来应该就清楚多了 |
Array.prototype._splice = function (start, delCount, ...addItems) {
const arr = this;
const res = [];
const left = arr.slice(0, start);
const right = arr.slice(start + delCount)
const remove = arr.slice(start, start + delCount); // 被删除的元素
arr.length = left.length;
addItems.forEach(item => arr.push(item));
right.forEach(item => arr.push(item));
return remove;
} |
你这个有问题,当start不小于0却大于数组长度的时候你这个会错误的导致数组长度变大 |
你的邮件我已收到,我会马上查看!
——————————————————————
现在的追逐梦想是为了日后能拥有美好的“那些年”!
|
Array.prototype._splice = function(start, delCount, ...addList) {
// 当起始位置超出了数组的长度,则从数组末尾开始添加内容
if(start > this.length) {
start = this.length;
delCount = 0;
}
if(start < 0) {
// 超出数组长度的话设置为0
if(Math.abs(start) > this.length) {
start = 0;
} else {
// 如果起始值为负数,则起始位置为数组末尾开始第几位
start += this.length;
}
}
// 设置删除的长度,没有值的话相当于移除起始位置之后的所有元素
if(delCount === undefined) {
delCount = this.length - start;
}
// 删除的元素
const removeList = this.slice(start, start + delCount);
// 删除元素的右侧数据
const right = this.slice(start + delCount);
// 将新加入的数据和右侧剩余的数据合并,然后将数组下标对应位置的元素替换
let addStart = start;
addList.concat(right).forEach(item => {
this[addStart] = item;
addStart++;
});
// 修改数组长度
this.length = addStart;
// 返回删除的元素
return removeList;
} 这里附上MDN对于这个方法的定义Array.prototype.splice() |
Array.prototype._splice = function (start, deleteCount, ...items) {
if (start < 0) {
start += this.length;
}
start = Math.max(start, 0);
if (deleteCount === 'undefined') {
deleteCount = this.length - start;
}
if (start >= this.length) {
deleteCount = 0;
}
deleteCount = Math.max(deleteCount, 0);
const length = this.length;
const right = [];
const deleted = [];
for (let i = start + deleteCount; i < length; i++) {
right.unshift(this.pop());
}
for (let i = start; i < start + deleteCount; i++) {
deleted.unshift(this.pop());
}
for (let i = 0; i < items.length; i++) {
this.push(items[i]);
}
for (let i = 0; i < right.length; i++) {
this.push(right[i]);
}
return deleted;
}; |
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/splice start deleteCount item1,item2,... 要插入的元素 |
你的邮件我已收到,我会马上查看!
——————————————————————
现在的追逐梦想是为了日后能拥有美好的“那些年”!
|
Array.prototype._splice = function(index, deleteCount, ...items) {
if (index < 0) {
index = this.length + index;
}
if (deleteCount === undefined) {
deleteCount = this.length - index;
}
if (deleteCount < 0) {
deleteCount = 0;
}
let res = this.slice(index, index + deleteCount);
let temp = [...this.slice(0, index), ...items, ...this.slice(index + deleteCount)];
if (temp.length < this.length) {
this.length = temp.length;
}
for (let i = 0; i < temp.length; i++) {
this[i] = temp[i];
}
return res;
}; |
function mySplice(start, deleteNum, ...newItem) {
// 传参检查与转换
if (typeof start !== "number" || deleteNum < 0) return [];
start < 0 && (start = Math.abs(this.length + start));
typeof deleteNum !== "number" && (deleteNum = this.length - start);
const removeList = this.slice(start, start + deleteNum),
newList = [
...this.slice(0, start),
...newItem,
...this.slice(start + deleteNum),
];
this.length += newItem.length - deleteNum;
let p = 0;
while (p < this.length) {
this[p] = newList[p++];
}
return removeList;
}
Array.prototype.mySplice = mySplice; |
No description provided.
The text was updated successfully, but these errors were encountered: