Nodejs Array Take takeSample()

Here you can find the source of takeSample()

Method Source Code

Array.prototype.takeSample = function () {
    var n = Math.round((Math.random() * (this.length - 1)));
    return this[n];
};

Related

  1. take(elements)
    Array.prototype.take = function(elements) {
        if (elements > this.length) {
            return [];
        } else {
            return this.slice(0, elements)
    
  2. take(howMany, f)
    Array.prototype.take = function(howMany, f){
       var counter = 0;
       var i = 0;
       var addIt = false;
       var newArray = [];
       while(counter < howMany && i < this.length){
           if(f == undefined){
               addIt = true;
           }else{
    ...
    
  3. take(length)
    Array.prototype.take = function (length) {
      var result = new Array();
      length = Math.min(this.length, length);
      for (var i = 0; i < length; i++)
        result.push(this[i]);
      return result;
    };
    
  4. take(n)
    Array.prototype.take = function (n) {
      return this.splice(0, n);
    };
    
  5. take(x)
    Array.prototype.take = function(x){
      return this.slice(0,x)
    
  6. takeUntil(fun)
    Array.prototype.takeUntil = function (fun) {
        var result = new Array(), index = 0;
        while (!fun(this[index])) {
            result.push(this[index++]);
        return result;
    };
    
  7. takeWhile(fun)
    Array.prototype.takeWhile = function (fun) {
        var result = new Array(), index = 0;
        while (fun(this[index])) {
            result.push(this[index++]);
        return result;
    };
    
  8. takeWhile(predicate)
    Array.prototype.takeWhile = function (predicate) {
      predicate = predicate || Predicate;
      var l = this.length;
      var arr = [];
      for (var i = 0; i < l && predicate(this[i], i) === true ; i++)
        arr.push(this[i]);
      return arr;
    };