I am trying to go through an array which contains multiple numbers and return an array which contains all those numbers but no duplicates. I have to use the reduce
& find
methods of JavaScript. How would I do this?
I attempted this:
var numbers = [1, 1, 2, 3, 4, 4];
function unique(numbers) {
var result = numbers.reduce(function(resultsArray, number) {
resultsArray.find(function(numberInResultsArray) {
if (numberInResultsArray === number) {
return true;
}
});
}, []);
return result;
}
unique(numbers);
...but it gives me a TypeError
:
TypeError: Cannot read property 'find' of undefined
It seems my array is not defined, but I don't understand why it wouldn't be. Any suggestions?