题目描述
var arr = [1, 2, 4, 1, 5, 5];
最终返回:[2, 4]
自己的CODE
const removeDuplicates = (newArr) => {
const obj = {};
for (let i = 0; i >= 0 && i < newArr.length; i += 1) {
if (newArr[i] in obj) {
newArr.slice(obj[newArr[i]], 1);
newArr.splice(i, 1);
i -= 2;
}
obj[newArr[i]] = i;
}
console.log(" result: ", newArr);
};
removeDuplicates(arr);
求大神指导最优解法