ES6 Set All In One Set 集合
数组去重
const arr = [1, 2, 3, 3, 2, 1];
const unique = [...new Set(arr)];
// [1, 2, 3]
const arr = [1, 2, 3, 3, 2, 1];
// unique = arr.reduce((acc, item) => !acc.includes(item) ? acc.concat([item]) : acc, []);
const unique = arr.reduce((acc, item) => {
if(!acc.includes(item)) {
acc.push(item);
}
return acc;
}, []);
// [1, 2, 3]