Nodejs Array Shuffle shuffle()

Here you can find the source of shuffle()

Method Source Code

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below./*from  w w w  . jav  a 2 s.c o  m*/
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//
//= require handlebars
//= require soundmanager
//
//= require_tree .

/**
 * Prototypes
 */
Array.prototype.shuffle = function() {
  var i = this.length, j, tempi, tempj;
  if ( i == 0 ) return false;
  while ( --i ) {
     j       = Math.floor( Math.random() * ( i + 1 ) );
     tempi   = this[i];
     tempj   = this[j];
     this[i] = tempj;
     this[j] = tempi;
  }
  return this;
}

Related

  1. shuffle()
    Array.prototype.shuffle = function() {
      var i = this.length, j, tempi, tempj;
      if ( i == 0 ) return false;
      while ( --i ) {
         j       = Math.floor( Math.random() * ( i + 1 ) );
         tempi   = this[i];
         tempj   = this[j];
         this[i] = tempj;
         this[j] = tempi;
    ...
    
  2. shuffle()
    Array.prototype.shuffle=function() {
      this.sort(function() { return Math.random()-0.5;});
    };
    Array.prototype.remove = function(from, to) {
      var array=this;
      var rest = array.slice((to || from) + 1 || array.length);
      array.length = from < 0 ? array.length + from : from;
      return array.push.apply(array, rest);
    };
    ...
    
  3. shuffle()
    Array.prototype.shuffle = function() {
      var currentIndex = this.length, temporaryValue, randomIndex;
      while (0 !== currentIndex) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
        temporaryValue = this[currentIndex];
        this[currentIndex] = this[randomIndex];
        this[randomIndex] = temporaryValue;
      return this;
    
  4. shuffle()
    Array.prototype.shuffle = function (){ 
        for(var j, x, i = this.length; i; j = Math.floor(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
        return this;
    };
    String.prototype.hashCode = function(){
      var hash = 5381;
      for (i = 0; i < this.length; i++) {
        char = this.charCodeAt(i);
        hash = ((hash<<5)+hash) + char;
    ...
    
  5. shuffle()
    Array.prototype.shuffle = function () {
      var i = this.length, j, temp;
      if ( i === 0 ) return false;
      while ( --i ) {
         j = Math.floor( Math.random() * ( i + 1 ) );
         temp = this[i];
         this[i] = this[j]; 
         this[j] = temp;
    
  6. shuffle()
    Array.prototype.shuffle = function() {
      var currentIndex = this.length, temporaryValue, randomIndex;
      while (0 !== currentIndex) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
        temporaryValue = this[currentIndex];
        this[currentIndex] = this[randomIndex];
        this[randomIndex] = temporaryValue;
      return this;
    
  7. shuffle()
    Array.prototype.shuffle = function() {
      var s = [];
      while (this.length)
        s.push(this.splice(Math.random() * this.length, 1));
      while (s.length)
        this.push(s.pop());
      return this;
    
  8. shuffle()
    var binarySearch = function(needle, haystack) {
        var low = 0,
            high = haystack.length - 1;
        haystack.sort(function(x, y) {
            return x - y;
        });
        while (low <= high) {
            var middle = Math.floor((low + high) / 2);
            if (needle === haystack[middle])
    ...
    
  9. shuffle()
    Array.prototype.shuffle = function (){
        var i = this.length, j, temp;
        if ( i == 0 ) return;
        while ( --i ) {
            j = Math.floor( Math.random() * ( i + 1 ) );
            temp = this[i];
            this[i] = this[j];
            this[j] = temp;
    };