JavaScript – Array Of Objects Unique/Remove Duplicates, With Support For Complex Objects (Such As DOM Elements)

JavaScript – array unique, with support for NodeList (the result of document.querySelectorAll), with support for custom “unique by” for array of objects by theirs properties (for example array or NodeList of <A> elements which can be uniquified or removed duplicates by their absolute HREF attribute)

The unique_by_fn is not restricted,
you can render any output (text recommended) to uniquely-identify an object, in the tmp {} storage.
-also the usage of {} and keys as a way of storing object is highly efficient!

Array.prototype.unique = function(unique_by_fn){  //optional: unique_by_fn to ""identify"" an object (for example "function(obj){return obj.href}" to unique identify <A> elements)
  var me  = this
     ,tmp
     ;

  tmp = me.reduce(function(carry, item){  //remove duplicates
    var unique_by = "function" === typeof unique_by_fn ? unique_by_fn(item) : item;
    carry[unique_by] = item;
    return carry;
  },{});

  tmp = Object.keys(tmp).map(function(key){
    return tmp[key];
  });

  return tmp;
}
NodeList.prototype.reduce = Array.prototype.reduce;
NodeList.prototype.unique = Array.prototype.unique;

function unique_by_href(element){
  return element.href || "";
}

var QUERY = 'div[id*="program-head"] div[class*="link-container"] a[href*="download_"][href*="download/"]';


document.querySelectorAll(QUERY)
        .unique(unique_by_href)
        ;

also available on this gist:
https://gist.github.com/eladkarako/65749e901e1bcf2c741db1be934e24f1.