This function removes all duplicate values from an array.
JavaScript:
let unique = arr.filter((value, index, self) => self.indexOf(value) === index);
// Example
console.log(unique([1, 2, 2, 3, 4, 4, 5])); // [1, 2, 3, 4, 5]
console.log(unique(['a', 'b', 'b', 'c', 'd', 'd'])); // ['a', 'b', 'c', 'd']
TypeScript:
let unique = arr.filter((value, index, self) => self.indexOf(value) === index);
// Example
console.log(unique([1, 2, 2, 3, 4, 4, 5])); // [1, 2, 3, 4, 5]
console.log(unique(['a', 'b', 'b', 'c', 'd', 'd'])); // ['a', 'b', 'c', 'd']