Nodejs Array Clone clone()

Here you can find the source of clone()

Method Source Code

/**// w w w  .  j av a2  s  .com
 * This file contains javascript codes that are shared across
 * all pages. You shouldn't be putting javascript codes here
 * if at least one page doesn't require them.
 */

// deep copies array
// copied from stackoverflow
// http://stackoverflow.com/questions/2294703/multidimensional-array-cloning-using-javascript
Array.prototype.clone = function() {
    var arr = this.slice();
    for(var i = 0; i < this.length; i++) {
        if(this[i].clone) {
            arr[i] = this[i].clone();
        }
    }
    return arr;
}

// generate a random integer
getRandNum = function(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

Related

  1. clone()
    Array.prototype.clone = function() {
      return this.slice(0);
    };
    var ArrayList = Array
    ArrayList.prototype.indexOfEdge = function(l){
      var i = 0;
      var found = false;
      while(i < this.length){
        if(l == this[i].label){
    ...
    
  2. clone()
    Array.prototype.clone = function () {
        var arr = [];
        for (var i = 0, len = this.length; i < len; i++) arr[i] = this[i];
        return arr;
    
  3. clone()
    Array.prototype.clone = function() {
      return this.slice(0);
    
  4. clone()
    Array.prototype.clone = function() {
      var arr = [];
      for (var i=0;i<this.length;i++) { arr.push(this[i]); }
      return arr;
    
  5. clone()
    Array.prototype.clone = function() {
        var result = new Array(this.length);
        var i = result.length;
        while(i--) { result[i] = this[i]; }
        return result;
    };
    function appendElementsToParentSelector() {
        var i, parent;
        if(arguments[0]) {
    ...
    
  6. clone()
    Array.prototype.clone = function()
        return slice.call(this, 0);
      };
    
  7. clone()
    Array.prototype.clone = function () {
      return this.slice(0);
    };
    
  8. clone()
    Array.prototype.clone = function() {
      return this.slice(0);
    };
    
  9. clone()
    Array.prototype.clone = function()
      return Array.prototype.slice.call(this, 0);