Nodejs Array Each each(f)

Here you can find the source of each(f)

Method Source Code

// Miscellaneous support code for Lecture 5

// Functional to create a new length-'count' array,
// by calling a function that many times, each time passing it the current index.
Array.create = function(f, count) {
    var arr = [];

    for (var i = 0; i < count; ++i) {
        arr.push(f(i));//from   w  w w .  j a  v  a  2  s.  c om
    }

    return arr;
}

// Call a function on every data value in an array, in order.
Array.prototype.each = function(f) {
    for (var i = 0; i < this.length; i += 1) {
        f(this[i]);
    }
};

// Call a function on every index and data value in an array, in order.
Array.prototype.eachi = function(f) {
    for (var i = 0; i < this.length; i += 1) {
        f(i, this[i]);
    }
};

// Step through an array in order, using a function to combine elements,
// beginning with an initial accumulator.
Array.prototype.reduce = function(f, acc) {
    this.each(function(x) { acc = f(x, acc); });
    return acc;
};

Related

  1. each(f)
    Array.prototype.each = function(f)
        for (var i = 0; i < this.length; i++)
            f(this[i])
        return this
    
  2. each(f)
    Array.prototype.each = function(f) {
      for(var i = 0, len = this.length; i < len; i++) {
        f(this[i]);
    };
    RegExp.escape = function(s) {
        return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
    };
    
  3. each(f)
    Array.prototype.each = function(f) {
        var res;
        for(var i = 0; i < this.length; i++) {
            res = f.call(i, this[i]);
        return res;
    
  4. each(f)
    Array.prototype.each = Array.prototype.each || function (f) {
      var i;
      for (i = 0; i < this.length; ++i) {
        f(this[i], i);
    };
    
  5. each(f)
    Array.prototype.each = function(f) {
      for(var i = 0; i < this.length; i++)
        f(this[i], i);
    };
    
  6. each(f)
    Array.prototype.each = function(f) {
        for (var i = 0; i < this.length; i++)f(this[i], i, this)
    };
    
  7. each(f)
    Array.prototype.each = function(f) {
      for (var i = 0; i < this.length; i++) {
        f(this[i], i);
    };
    
  8. each(f)
    Array.prototype.each = function(f) {
      for (var i = 0; i < this.length; ++i) {
        f(this[i]);
      return this;
    
  9. each(f, callback)
    var crypto = require('crypto')
    var http = require('http');
    Array.prototype.each = function(f, callback) {
        for (var i = 0, l = this.length; i < l; i++) {
            f(this[i]);
        if (callback) callback();
    Array.prototype.asyncEach = function(f, callback, i) {
    ...