Skip to content

Instantly share code, notes, and snippets.

@fliptopbox
Last active August 25, 2015 21:37
Show Gist options
  • Save fliptopbox/ed8b515d39ef846041dd to your computer and use it in GitHub Desktop.
Save fliptopbox/ed8b515d39ef846041dd to your computer and use it in GitHub Desktop.

Revisions

  1. fliptopbox renamed this gist Aug 25, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. fliptopbox revised this gist Aug 25, 2015. No changes.
  3. fliptopbox created this gist Aug 25, 2015.
    12 changes: 12 additions & 0 deletions Javascript: Array.shuffleAndClip
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    Array.prototype.shuffleAndClip = function (len) {
    var array = this;
    if(len && array.length && len > array.length - 1) {
    len = null;
    }
    for(var rnd, value, i = array.length; i;
    rnd = Math.floor(Math.random() * i),
    value = array[--i],
    array[i] = array[rnd],
    array[rnd] = value);
    return len ? array.slice(0, len) : array;
    }