Felix Riesterer: JavaScript Array

Beitrag lesen

Lieber Gunnar,

ja, Fisher-Yates. In meinem R-Quiz habe ich 2017 genau den verwendet:

/**
 * function to shuffle an array
 *
 * http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array#answer-25984542
 *
 * @param Array input
 */
shuffleArray: function (array) {
	var count = array.length, r, temp;

	while (count) {
		r = Math.random() * count-- | 0;
		temp = array[count];
		array[count] = array[r];
		array[r] = temp;
	}
},

Liebe Grüße

Felix Riesterer