Javascript Array accumulate(accumulator)

Description

Javascript Array accumulate(accumulator)


Array.prototype.accumulate = function(accumulator) {
  if (typeof Array.prototype.map == 'function') {
    return this.map(accumulator);
  }/*  w w w  .ja  v a2s . c  om*/

  var out = [];
  var end = this.length;

  for (var i = 0; i < end; i++) {
    out.push(accumulator(this[i]));
  }

  return out;
};



PreviousNext

Related