With the help of some nice folks at Stack Overflow, I wrote an algorithm that will give a user three buttons: option a
neither
option b
Clicking on a button will add one to the score of a object, and it will systematically go through each match-up to get an equal amount of questions for each character.
Here's the meat of the function:
var pos1 = 0; //position in the array
var pos2 = 1; //ditto
var array = [ //array used
{name: "apple", score: 0},
{name: "pear", score: 0},
{name: "cherry", score: 0},
{name: "banana", score: 0},
{name: "orange", score: 0},
{name: "watermelon", score: 0},
{name: "bread" score: 0},
{name: "a duck" score: 0}
]
var option1 = array[0]; //keeps track of which option is shown in the button
var option2 = array[1]; //ditto
function select(slot) { //called when user presses button
if (slot == 1) { //left button
array[pos1].score++;
} else if (slot == 2) { //right button
array[pos2].score++;
} //for neither, it does select(0)
if (pos2 < array.length - 1) {
pos2++;
option2 = array[pos2];
} else if (pos1 < array.length - 2) {
pos1++;
pos2 = 1 + pos1;
option1 = array[pos1]
option2 = array[pos2]
} else {
output(); //sorts and displays
return;
}
}
It works pretty well for smaller numbers of objects, but it gets totally absurd at higher numbers. For example, in practice, one of my sets has around 50 objects, resulting in ~1500 questions, which takes hours!
As a side note, I found this website. Ignoring the content, it's able to sort a similar number (55) of objects with only 170 questions. It's also somehow able to generate a percentage of completion, but that's just a bonus.
Conveniently, the author has the code embedded directly in the HTML, so the JavaScript is easy to view. However, I can't figure out how it works, but it's the type of efficiency I'm looking for.