一般做法
const unique = (arr) => {
const result = arr.reduce((acc, iter) => {
if(acc.indexOf(iter) === -1) {
acc.push(iter)
}
return acc
}, [])
return result
}
超前做法
const unique = (arr) => {
return [...new Set(arr)]
}
const unique = (arr) => {
const result = arr.reduce((acc, iter) => {
if(acc.indexOf(iter) === -1) {
acc.push(iter)
}
return acc
}, [])
return result
}
const unique = (arr) => {
return [...new Set(arr)]
}