Skip to content

Instantly share code, notes, and snippets.

@coffeetocode
Created October 1, 2016 22:14
Show Gist options
  • Save coffeetocode/9eb9780a05d37c2ee150568ed2436c61 to your computer and use it in GitHub Desktop.
Save coffeetocode/9eb9780a05d37c2ee150568ed2436c61 to your computer and use it in GitHub Desktop.
const_arr = ["Erin Ptacek", "Thomas Ptacek", "Jeremy Rauch"]
arr = []
var results = {"Erin Ptacek": {0:0, 1:0, 2:0},
"Thomas Ptacek": {0:0, 1:0, 2:0},
"Jeremy Rauch": {0:0, 1:0, 2:0},
};
// custom sort function definition equiv to "x-y"
function randsort(x, y) {
console.log("[*] State of arr:" + arr);
console.log("[*] Comparing "+x+" to "+y);
var ret = 1 - Math.ceil(Math.random() * 100) % 3;
console.log("[*] ret is "+ret);
if(ret > 0) {
console.log("[*] this will result in a swap");
}
return ret;
}
for(var i = 0; i < 10; i++) {
arr = [].concat(const_arr); //poor man's deep copy
arr.sort(randsort);
console.log("Sort finished, order is:"+arr);
for(var name in results) {
results[name][arr.indexOf(name)]++;
}
if(i % 1000 == 0) {
console.log(i);
}
}
for(var name in results) {
console.log(name);
console.log(results[name]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment