I'm trying to achieve to write an array function with the use of reduce and find helpers that returns an array of unique numbers.
var numbers = [1, 1, 2, 3, 4, 4];
// function should return [1, 2, 3, 4]
function unique(array) {
array.reduce((uniqueArray, number) => {
if (uniqueArray.indexOf(find(array.number))) {
uniqueArray.push(array.number);
}
return uniqueArray;
}, []);
}
console.log(unique(numbers));
// undefined
// undefined
When running this code I get
undefined
twice in Browser Javascript console.