Skip to content

Instantly share code, notes, and snippets.

@fabiomontefuscolo
Created May 30, 2016 13:58
Show Gist options
  • Save fabiomontefuscolo/6a2c8cb4bbee9f228cb438b7ec15bbd8 to your computer and use it in GitHub Desktop.
Save fabiomontefuscolo/6a2c8cb4bbee9f228cb438b7ec15bbd8 to your computer and use it in GitHub Desktop.
(function ($) {
$.shuffle = function shuffle(array) {
if(!array) {
if ($.isArray(this)) {
array = this
} else {
array = $(this);
}
}
var i = array.length;
var temp = null;
var rand = null;
while (0 !== i) {
rand = Math.floor(Math.random() * i);
i -= 1;
temp = array[i];
array[i] = array[rand];
array[rand] = temp;
}
return $(array);
};
$.fn.shuffle = function () {
return $.shuffle(this);
};
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment