Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Remove duplicates from arrays using reduce

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Remove #duplicates #arrays #reduce
ADD COMMENT
Topic
Name
8+4 =