You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
933 B
48 lines
933 B
/**
|
|
*
|
|
*/
|
|
var Sorter = function() {};
|
|
|
|
// NOTE fisher-yates, http://bost.ocks.org/mike/algorithms/
|
|
/**
|
|
* Returns copy of an array shuffled using Fisher-Yates.
|
|
*/
|
|
Sorter.prototype.shuffle = function(arr) {
|
|
var result = Object.create(arr);
|
|
var n = result.length, t, i;
|
|
while (n) {
|
|
i = Math.random() * n-- | 0; // 0 ≤ i < n
|
|
t = result[n];
|
|
result[n] = result[i];
|
|
result[i] = t;
|
|
}
|
|
return result;
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
Sorter.prototype.generate = function(n) {
|
|
var arr = [];
|
|
for (var i = 0; i < n; i++) {
|
|
arr.push({
|
|
value: Math.floor(i * 255 / n),
|
|
});
|
|
};
|
|
|
|
return arr;
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
Sorter.prototype.sort = function(instruction) {
|
|
throw new Error('Sorter.sort() method override required.');
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
Sorter.prototype.addInstruction = function(instruction) {
|
|
throw new Error('Sorter.addInstruction() method override required.');
|
|
};
|
|
|