code: function uniqueCountryData(data, type, parent) {
    var hash = data.reduce(function each(prev, curr) {
      if (!(curr[type] in prev)) {
        if (parent) {
          if (parent.label === curr[parent.type]) {
            prev[curr[type]] = curr;
          }
        } else if (curr[type]) {
          prev[curr[type]] = curr;
        }
      }
  
      return prev;
    }, {});
  
    return Object.keys(hash).map(function each(item) {
      return extend(hash[item], {
        label: item,
        type: type === 'name' ? 'country' : type
      });
    });
  }
docs: transform rest country data for example