Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Ranges in CoffeeScript enable us to easily populate an array with numbers ranging from a start number to an end number. The syntax for building a range looks like so:
Example: (source: range1.coffee)
myRange = [1..10]
console.log myRange
(function() {
var myRange;
myRange = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log(myRange);
}).call(this);
Output: (source: range1.coffee)
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
By separating the start number and the end number with .. we will get an array filled with numbers, starting with the first number and going up to and including the end number. If we want to exclude the end number, we would use ... instead of ..:
Example: (source: range2.coffee)
myRange = [1...10]
console.log myRange