Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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