This is well-traveled territory. Whatever is or is not implemented, interfaces which have optional arguments and return scalars in one case and arrays in another case are a horrible idea.
To my knowledge no-one has ever explained why the following is a bad idea: ``` array.0 array.-1 ``` Bob On Tue, Sep 27, 2016 at 5:42 PM, Nicu Micleusanu <[email protected]> wrote: > I propose to standardize `Array.prototype.first()` and > `Array.prototype.last()`, very similar to underscore `_.first()` and > `_.last()`. > > > A very basic implementation: > > ```js > > Array.prototype.first = function (n) { > > if (!arguments.length) { > > return this[0]; > > } else { > > return this.slice(0, Math.max(0, n)); > > } > > }; > > > Array.prototype.last = function (n) { > > if (!arguments.length) { > > return this[this.length - 1]; > > } else { > > return this.slice(Math.max(0, this.length - n)); > > } > > }; > > ``` > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

