const names = [
'shibu',
'neymar',
'vinicius',
'pattinson',
'ronaldo',
'shibu',
'neymar',
'pattinson',
'diCaprio'
];
let onlyName = names.reduce((accumulator, currentValue) => {
if (accumulator.indexOf(currentValue) === -1) {
accumulator.push(currentValue);
}
return accumulator;
}, []);
console.log(onlyName);
//Expected result => ['shibu', 'neymar', 'vinicius', 'pattinson', 'ronaldo', 'diCaprio'
var numbers = [1, 1, 2, 3, 4, 4];
function unique(array){
return array.reduce(function(previous, current) {
if(!previous.find(function(prevItem){
return prevItem === current;
})) {
previous.push(current);
}
return previous;
}, []);
}
unique(numbers);