1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Documenting default slice indexes.

This commit is contained in:
clutchski 2012-01-26 15:57:27 -05:00
parent c0dac45fe1
commit d74c909930
2 changed files with 7 additions and 3 deletions

View file

@ -1,7 +1,9 @@
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
copy = numbers[0...numbers.length]
start = numbers[0..2]
middle = copy[3..6]
middle = numbers[3...6]
end = numbers[6..]
copy = numbers[..]

View file

@ -558,6 +558,8 @@ Expressions
Ranges can also be used to extract slices of arrays.
With two dots (<tt>3..6</tt>), the range is inclusive (<tt>3, 4, 5, 6</tt>);
with three dots (<tt>3...6</tt>), the range excludes the end (<tt>3, 4, 5</tt>).
Slices indices have useful defaults. An omitted first index defaults to
zero and an omitted second index defaults to the size of the array.
</p>
<%= code_for('slices', 'middle') %>
<p>