Nodejs Array Take takeWhile(predicate)

Here you can find the source of takeWhile(predicate)

Method Source Code

Array.prototype.takeWhile = function (predicate) {
   predicate = predicate || Predicate;// w  w  w  .  jav  a2  s .c  o m
   var l = this.length;
   var arr = [];
   for (var i = 0; i < l && predicate(this[i], i) === true ; i++)
      arr.push(this[i]);

   return arr;
};

Related

  1. take(n)
    Array.prototype.take = function (n) {
      return this.splice(0, n);
    };
    
  2. take(x)
    Array.prototype.take = function(x){
      return this.slice(0,x)
    
  3. takeSample()
    Array.prototype.takeSample = function () {
        var n = Math.round((Math.random() * (this.length - 1)));
        return this[n];
    };
    
  4. takeUntil(fun)
    Array.prototype.takeUntil = function (fun) {
        var result = new Array(), index = 0;
        while (!fun(this[index])) {
            result.push(this[index++]);
        return result;
    };
    
  5. takeWhile(fun)
    Array.prototype.takeWhile = function (fun) {
        var result = new Array(), index = 0;
        while (fun(this[index])) {
            result.push(this[index++]);
        return result;
    };