Feature-Request: Add Range type data

# Dayvson Lima (8 years ago)

Example:

var myRange = new Range(0,4);

myRange == (0..4) #=> true

new Array(myRange) #=> [0, 1, 2, 3, 4]

var charRange = new Range('a', ' d'); #=> ('a'..'d')

new Array(myRange) #=> ['a', 'b', 'c', 'd']

# Jordan Harband (8 years ago)

new Array(myRange) could never work, but [...myRange] could.

# Steve Fink (8 years ago)

On 07/14/2016 09:33 PM, Dayvson Lima wrote:

Example:

var myRange = new Range(0,4);

myRange == (0..4) #=> true

This (0..4) syntax doesn't exist, afaik. Do you mean myRange == [0,1,2,3,4]? Given that [1,2] != [1,2], I don't think so. I'm assuming you meant that as shorthand.

new Array(myRange) #=> [0, 1, 2, 3, 4]

I'm not sure what this gives you over

var Range = function*(start, end) { let i = start; while (i <= end) yield i++; };

var myRange = Range(0, 4); new Array(myRange); # [0, 1, 2, 3, 4], but it empties out myRange [...Range(0, 4)]; # [0, 1, 2, 3, 4]

var charRange = new Range('a', ' d'); #=> ('a'..'d')

Ugh. This is very latin1-centric. What is 'a'..'d', again? a ä á à b ç c d, perhaps? (Yes, charCodeAt(0) offers a possible interpretation, but it's somewhat random.) And what is Range('aa', 'bb')? Range('a', 'bb')? Range('A', 'a')? Keep away from characters; they aren't numbers drawn from any useful 1-dimensional space.

# Dayvson Lima (8 years ago)

this feature request is inspired by the successful Range object behavior in ruby language

ruby-doc.org/core-2.2.0/Range.html

the intention is to have something like interface to work with value ranges

2016-07-15 14:35 GMT-03:00 Steve Fink <sphink at gmail.com>: