Javascript Array inject(command, accumulator)

Description

Javascript Array inject(command, accumulator)


Array.prototype.inject = function(command, accumulator){
  var start = 0;/*from w w  w.j  a  va2 s .  co  m*/
  if(!accumulator){
    accumulator = this[0]
    start += 1;
  }

  this.slice(start,this.length).each(function(el){
    accumulator = command(accumulator, el);
  });

  return accumulator;
}



PreviousNext

Related