function removeWithoutCopy(arr, item) { let length = arr.length while (length--) { if (arr[length] === item) { arr.splice(length, 1) } } return arr }
// 递归思想 function removeWithoutCopy(arr, item) { if (arr.indexOf(item) === -1) return arr; arr.splice(arr.indexOf(item), 1); removeWithoutCopy(arr, item); return arr }
function removeWithoutCopy(arr, item) { return arr.filter(value=>{ return value != item }) }为什么不行?
function removeWithoutCopy(arr, item) { while(arr.indexOf(item) !=-1){ var index = arr.indexOf(item) arr.splice(index,1) } return arr }