Nodejs Array Where where(exp)

Here you can find the source of where(exp)

Method Source Code

Array.prototype.where = function(exp){
    var exp = new Function("$", "return " + exp);
    var arr=[];/*from  w  w w  .  j ava 2 s  .  co  m*/
    for(var i=0; i<=this.length-1; i++){
        if(exp(this[i])){
            arr.push(this[i])
        }
    }
    return arr;
};

Array.prototype.collect = function(exp){
    var exp = new Function("$", "return " + exp);
    var arr=[];
    for(var i=0; i<=this.length-1; i++){
        arr.push(exp(this[i]))
    }
    return arr;
};
Array.prototype.join = function(arr){
    this.joined_data = arr;
    return this;
};

Array.prototype.as = function(key,exp){
    var exp = new Function("$",key, "return " + exp);
    var arr=[];
    
    for(var i=0; i<=this.length-1; i++){
        for(var j=0; j<=this.joined_data.length-1; j++){
            if(exp(this[i], this.joined_data[j])){
                var obj = {};
                for(var k in this[i]) {
                    if((this[i]).hasOwnProperty(k)) {
                        obj[k] = this[i][k]
                    }
                }
                obj[key] = this.joined_data[j];
                arr.push(obj)
                //this[i][key]=this.joined_data[j];
            }
        }
    }
    return arr;
};

Related

  1. where(_cond)
    Array.prototype.where = function (_cond) {
        var items = []; 
        for (var l = 0; l < this.length; l++) {
            if (_cond(this[l])) {
                items.push(this[l]);
        return items;
    };
    ...
    
  2. where(argument)
    Array.prototype.where = function(argument) {
      return this.filter(item => argument(item));  
    };
    
  3. where(attribut, value)
    Array.prototype.where = function (attribut, value) {
        var res = [];
        for (var i = 0; i < this.length; i++) {
            if (this[i][attribut] == value)
                res.push(this.slice(i, i + 1));
        return res;
    };
    
  4. where(callback)
    Array.prototype.where = function(callback){
      if(!callback) return;
      for(var i = 0; i < this.length; i++){
        if(callback(this[i])){
          return this[i];
    
  5. where(f)
    Array.prototype.where = function(f){
       var fn = f;
       if(typeof f == 'string'){
          if((fn=lambda(fn)) == null){
             throw "Syntax error in lambda string: "+ f;
    };
    
  6. where(f)
    Array.prototype.where = function(f){
        var newArray = [];
        for(var i = 0; i < this.length; i++){
            if(f(this[i])){
                newArray.push(this[i]);
        return newArray;
    };
    ...
    
  7. where(func)
    Array.prototype.where = function(func) {
      var result = [];
      for (var i = 0; i < this.length; i++)
        if (func(this[i]))
          result.push(this[i]);
      return result;
    };
    
  8. where(func)
    Array.prototype.where = function(func){
      var result = [];
      forEach(this, function (element) {
        if(func(element)){
          result.push(element);
      });
      return result;