题解 | #查找重复元素#
查找重复元素
http://www.nowcoder.com/practice/871a468deecf453589ea261835d6b78b
let arr = [1, 2, 4, 4, 3, 3, 1, 5, 3]
function foo(arr) {
let newArr = []
arr.sort()
for(let i = 0; i < arr.length; i++) {
if(arr[i]=== arr[i+1]){
newArr.push(arr[i])
}
}
return newArr.filter((item,index) => {
return newArr.indexOf(item) === index
})
}
console.log(foo(arr));