Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
  <script>
 
    
    //Data:
    var   maleTotal = 48840  , femaleTotal = 10741,
          maleSample = 25000 , femaleSample = femaleTotal,
          hiring = 5000;
        
   
    
    //sources:
                 // https://nces.ed.gov/programs/digest/d16/tables/dt16_322.40.asp?current=yes
                // https://nces.ed.gov/programs/digest/d16/tables/dt16_322.50.asp?current=yes
     
    
// copied from stack overflow  
    // returns a gaussian random function with the given mean and stdev.
function gaussian(mean, stdev) {
    var y2;
    var use_last = false;
    return function() {
        var y1;
        if(use_last) {
           y1 = y2;
           use_last = false;
        }
        else {
            var x1, x2, w;
            do {
                 x1 = 2.0 * Math.random() - 1.0;
                 x2 = 2.0 * Math.random() - 1.0;
                 w  = x1 * x1 + x2 * x2;               
            } while( w >= 1.0);
            w = Math.sqrt((-2.0 * Math.log(w))/w);
            y1 = x1 * w;
            y2 = x2 * w;
            use_last = true;
       }
       var retval = mean + stdev * y1;
       if(retval > 0) 
           return retval;
       return -retval;
   }
}
// make a standard gaussian variable.     
var standard = gaussian(100, 15);
   console.log("there are "+maleTotal+" males, we will pick only "+maleSample+"("+100*maleSample/maleTotal+"%)");
   console.log("we will pick all females to represent the company reaching out to them");
 var males=[];
    for(var i=0 ; i < maleSample;i++)males[i]=standard();
 var females=[];
    for(var i=0 ; i < femaleSample;i++)females[i]=standard();
 var   nFemales = 0;
 var   nMales = 0;
  var currentFemale = femaleSample - 1;
  var currentMale = maleSample - 1;
 males.sort(function(a, b) {
  return a - b;
});
 females.sort(function(a, b) {
  return a - b;
});
   
 console.log("let's say the company is going to hire 5000");
    
    var hire = hiring;
    var sumMale = 0;
    var sumFemale = 0;
 console.log("hiring based on competence and taking females when equal");
 while(hire > 0){
   if(males[currentMale] <= females[currentFemale]){
     //notice the use of  comparison to favor females
      sumFemale+=females[currentFemale];
     --currentFemale;
     ++nFemales;
     
     
     
   }else{
      sumMale+=males[currentMale];
     --currentMale;
     ++nMales;
    
   }
   
   
   --hire;
   
 }
console.log("results:");
console.log("male: number: "+nMales+" percentage: "+100*nMales/hiring +"% average score: "+ sumMale/nMales);
 console.log("female: number: "+nFemales+" percentage: "+100*nFemales/hiring +" average score: "+ sumFemale/nFemales);
   
    console.log("if we force the 50% ratio");
   // find the average of  the best   males 
    var sum = 0;
    for(i=1; i <= hiring / 2 ; ++i) sum+=males[maleSample - i];
    console.log("the average male score: "+ sum/(hiring/2));
   // find the average of  the best  females 
    sum = 0;
    for(i=1; i <= hiring / 2 ; ++i) sum+=females[femaleSample - i];
    console.log("the average female score:  "+ sum/(hiring/2));
    
  
    
  
   
 
    
  
   
   
 
    
    
    
  </script>
<body>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers