chekit
2/26/2018 - 11:17 AM

reduces digits array from repeated items to unique items only

reduces digits array from repeated items to unique items only

// Reduces digits array from repeated items to unique items only
const arr = [1, 2, 1, 1, 4, 5, 7, 8, 2];
const unique = arr.filter((item, index, arr) => index === arr.indexOf(item));

console.log(unique); // [1, 2, 4, 5, 7, 8]

// Alternative
const unique2 = Array.from(arr.reduce((acc, item) => acc.add(item), new Set()));

console.log(unique2); // [1, 2, 4, 5, 7, 8]