* 移除数组 arr 中的所有值与 item 相等的元素,直接在给定的 arr 数组上进行操作,并将结果返回
input:[1, 2, 2, 3, 4, 2, 2], 2 output: [1, 3, 4]
function removeWithoutCopy(arr, item) { var stack = [], last; while (arr.length > 0) { last = arr.pop(); if (last !== item) { stack.push(last); } } while (stack.length > 0) { arr.push(stack.pop()); } return arr; }
https://www.nowcoder.com/practice/a93dd26ebb8c425d844acc17bcce9411?tpId=6&tqId=10952&rp=1&ru=%2Fta%2Fjs-assessment&qru=%2Fta%2Fjs-assessment%2Fquestion-ranking