Array reduce from Right - Node.js Array

Node.js examples for Array:Array Operation

Description

Array reduce from Right

Demo Code


Array.prototype.reduceRight = function reduceRight(callback, initialValue) {
  var array = this, previousValue = initialValue || 0;

  for (var index = array.length - 1; index > -1; --index) {
    previousValue = callback.call(window, previousValue, array[index], index, array);
  }//from w  ww  . ja v a 2s  . c  om

  return previousValue;
};

Related Tutorials