On Sun, Dec 23, 2012 at 8:35 PM, Brandon Benvie
<[email protected]>wrote:
> Here's one of the examples that was sticking out in my mind earlier that
> Brendan's solution takes care of. Array.prototype.reduce requires that if
> the initial value isn't provided then the first value of the array is the
> initial value.
>
> Using rest:
>
> function reduce(callback, ...initial){
> var current, index;
>
> if (initial.length) {
> index = 0;
> current = initial[0];
> } else {
> index = 1;
> current = this[0];
> }
>
> ...etc...
> }
>
>
> Using arguments.length:
>
> function reduce(callback, initial){
> var current, index;
>
> if (arguments.length > 1) {
> index = 0;
> current = initial;
> } else {
> index = 1;
> current = this[0];
> }
>
> ...etc...
> }
>
>
>
> I guess using rest like that is not a bad way to solve it, though it's not
> saying what you mean but rather kind of hacking around the limitation.
> Either way, it's certainly possible to forgo using arguments to accomplish
> the goal.
>
In the case of reduce, the specification algorithm names an identifier in
the formal parameter list: initialValue, so what is preventing your
implementation from doing initial !== undefined?
Rick
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss