i'm working on writing a generic utility that will remove duplicates from an array in javascript. I have the following code where what's desired actually works. I'd like to then turn it into a utility. The 1st block of code works, the 2nd is the utility, and the 3rd is how I am trying to apply the utility (doesn't work - the duplicates from the array still appear). Any insight would be super appreciated.
//Code without utility - works//
var productArr = [];
for (var p in theData) {
  var theProduct = theData[p];
  var theProductSelect = productArr.filter(function(value, index, self) {
    return self.indexOf(value) === index;
  });
  productArr.push(theProduct.name);
}
//Here's the utility I am trying to write
publicMethods.deDuplicate = function(array, key, type) {
  var providedArray = [];
  var uniqueArray = providedArray.filter(function(value, index, self) {
    return self.indexOf(value) === index;
    return providedArray;
  });
};
//Code with Utility - duplicates still appear
var productArr = [];
for (var p in theData) {
  var theProduct = theData[p];
  productArr.push(theProduct.name);
  publicMethods.deDuplicate(productArr)
}
 
     
     
    