I need to create a findUnique()
function that creates a new array with non-repeating values.
This is how it should be:
console.log([10, 5, 6, 10, 6, 7, 2].findUnique()) // [5, 7, 2]
My try:
Array.prototype.findUnique = function() {
let arr = this;
let newarr = arr.filter((v, i, a) => {
return a.indexOf(v) === i
})
return newarr
}
But it returns:
[10, 5, 6, 7, 2]
How can I make it return only non-repeated values?