Created
May 30, 2016 13:58
-
-
Save fabiomontefuscolo/6a2c8cb4bbee9f228cb438b7ec15bbd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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