demo/full/scripts/lib/shuffleArray.js
/**
 * Shuffle members of an array into a random order.
 * @param {Array.<*>} arr
 * @returns {Array.<*>}
 */
Shuffle members of an array into a random order.
Shuffle members of an array into a random order .
function shuffleArray(arr) {
  const clonedArr = arr.slice();
  let currentIndex = arr.length;
  while (0 !== currentIndex) {
    const randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
    const temporaryValue = clonedArr[currentIndex];
    clonedArr[currentIndex] = clonedArr[randomIndex];
    clonedArr[randomIndex] = temporaryValue;
  }
  return clonedArr;
}
function shuffleArray ( arr ) { const clonedArr = arr . slice ( ) ; let currentIndex = arr . length ; while ( 0 !== currentIndex ) { const randomIndex = Math . floor ( Math . random ( ) * currentIndex ) ; currentIndex -= 1 ; const temporaryValue = clonedArr [ currentIndex ] ; clonedArr [ currentIndex ] = clonedArr [ randomIndex ] ; clonedArr [ randomIndex ] = temporaryValue ; } return clonedArr ; }
Shuffle members of an array into a random order.
Shuffle members of an array into a random order .
// Pick a remaining element... // And swap it with the current element.