<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |