参考答案:
Array.prototype.distinct = function() {
var ret = [];
for (var i = 0; i < this.length; i++) {
for (var j = i + 1; j < this.length;) {
if (this[i] === this[j]) {
ret.push(this.splice(j, 1)[0]);
} else {
j++;
}
}
}
return ret;
};
let arr = ["a", "b", "c", "d", "b", "a", "e"];
console.log(arr.distinct()); // ['a', 'b']
console.log(arr); // ['a', 'b', 'c', 'd', 'e']
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。