im working on a experiment with about 90 html pages and i need to be able to generate 90 possible adapts(or possibilities) to be loaded one in each page for the participant to give inout to..of corse it wont go on internet but it is client-server based experiment. Now here is what i have so far.
var freqPos = 45;
var freqNeg = 45;
var freqNeut = 45;
var pool = Array();
for (i = 0; i < freqPos; i++) {
pool.push(1);
}
for (i = 0; i < freqNeg; i++) {
pool.push(-1);
}
for (i = 0; i < freqNeut; i++) {
pool.push(0);
}
function meraFub(id) {
var a;
//do somthing with CSS classes
});
shuffle(pool);
console.log(pool);
if (pool.length > 0 ) {
if (pool[0] === -1 ) {
a ='2';
//do somthing with CSS classes
}
else if (pool[0] === 1) {
a ='3';
//do somthing with CSS classes
}
else if (pool[0] === 0) {
a ='4';
//do somthing with CSS classes
}
}
else {
console.log("YOU ARE EMPTY");
console.log(pool);
}
console.log(pool.shift());
console.log(pool);
var result = {};
result.adapt = a;
ajaxCall("/log/adapt", result);
return false;
}
and am using the Fischer Yates shuffle algo to shuffle the 90 adapts or possibilites that i want the participant to give his input against. which happen to be working fine but since its every time a new html page opening the array re-initializes itself and stays at 89. Following is the algo im using for shuffle
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
According to Stackoverflow pages i read that it could be done with param(); or with passing array via URL parameter..But since im new to JS/Jquery i really have no idea how to do that. Your help will be highly appreciated. Thanks a lot in advance.