Setting initialValue of Array.prototype.reduce with a default argument

Nelo Mitranim me at
Thu Feb 25 06:11:47 UTC 2016

Changing `Array.prototype` isn’t worth the effort. Write your own reduce function that does exactly what you want:

function foldr (list, func, acc) {
  for (let i = list.length; --i >= 0;) acc = func(acc, list[i], i)
  return acc

This will default the initial value to `undefined` and let you omit it.

More information about the es-discuss mailing list