Array.range() (was: Suggestion: Array.prototype.repeat)

Axel Rauschmayer axel at rauschma.de
Tue Jan 3 09:42:02 PST 2012


> I think it's fairly common for range implementations to provide an optional `step` parameter

Good point. Maybe all of these parameters should be options:

Array.range() -> 0, 1, 2, 3, ...
Array.range({ start: 3 }) -> 3, 4, 5, 6, ...
Array.range({ end: 5 }) -> 0, 1, 2, 3, 4
Array.range({ step: 3 }) -> 0, 3, 6, 9, ...
Array.range({ start: -2, step: -1 }) -> -2, -3, -4, -5, ...
etc.

The defaults of start and end and the comparison operator depend on the sign of step.

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120103/5af14e75/attachment-0001.html>


More information about the es-discuss mailing list