Array.prototype.reduce() in JavaScript