I am doing some online coding challenges and i was wondering if anyone had a better way of writing a solution for this.
Write a function called 'unique' that will remove all duplicates values from an array.
var numbers = [1, 1, 2, 3, 4, 3,9,0,9];
return array.reduce(function(previous, num){
var checkForRepeat = previous.find(function(x){
return x === num;
});
if(checkForRepeat) {
return previous;
} else {
previous.push(num);
return previous;
}
}, []);
}
unique(numbers);