Skip to content

Instantly share code, notes, and snippets.

@wcoder
Created May 24, 2014 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wcoder/47e9a35d6cdaf7110fe4 to your computer and use it in GitHub Desktop.
Save wcoder/47e9a35d6cdaf7110fe4 to your computer and use it in GitHub Desktop.
(function(){
// by https://gist.github.com/wcoder/10601500
var shuffleArray = function (array) {
for (var j, x, i = array.length; i;)
{
j = j = parseInt(Math.random() * i);
x = array[--i];
array[i] = array[j];
array[j] = x;
}
return array;
};
$.fn.shuffle = function() {
var that = this,
list = that.children(),
shuffledList = shuffleArray(list);
that.empty();
shuffledList.each(function(index, element){
that.append(element);
});
return that;
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment