题目描述
移除数组 arr 中的所有值与 item 相等的元素,请直接在给定的 arr 数组上进行操作
输入例子:
removeWithoutCopy([1, 2, 2, 3, 4, 2, 2])
输出例子:
[1, 3, 4]
function removeWithoutCopy(arr, item) {
var pos =0;while(pos < arr.length)
{
pos =arr.indexOf(item,pos);
if(pos == -1) break;
arr.splice(pos,1);
if( arr.length !=0)
{
removeWithoutCopy(arr,item);
}
}
return arr;
}