JSFiddle - React, Tailwind, and code Playground

by LuckyCat

JavaScript

Array.prototype.shuffle = function( b )

{

 var i = this.length, j, t;

 while( i ) 

 {

  j = Math.floor( ( i-- ) * Math.random() );

  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];

  this[i] = this[j];

  this[j] = t;

 }

 return this;

};

// Перемешивание одномерного массива

var a = new Array(1,2,3,4,5);

alert( a.shuffle() );

//Перемешать включая вложенные массивы

alert( ['a','b','c', [1,2,3,4,5], 'D','E','F'].shuffle(true) );