Q:

How do I make an array of another array's duplicate values only in Javascript? 

I have an array with registrants from multiple companies (some from the same companies, some not) and I need to count how many people from the same company have registered.  So I need a number that tells me how many extra people (after the first) from unique companies have registered.  
Say I have an array:
var company_names = ['acme', 'acme', 'bobo', 'comanche', 'acme', 'comanche'];

and a variable:
var companies_eligible_for_discount = 0;

How would I count that 3 discounts are to be assigned? ( 2 for "acme" and 1 for "comanche")

A:

var dupes = {};

company_names.forEach(function(v,i) {
    if( v in dupes ) {
        dupes[v]++;
        companies_eligible_for_discount++;
    }
    else dupes[v] = 0;
});

var dupes = {}, v, i;

for( i = 0; i < company_names.length; ++i ) {
    v = company_names[i];
    if( v in dupes ) {
        dupes[v]++;
        companies_eligible_for_discount++;
    }
    else dupes[v] = 0;
}

