mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-12 09:44:24 +02:00
array first and last methods
This commit is contained in:
@@ -155,6 +155,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
|
|||||||
# Arrays can be indexed
|
# Arrays can be indexed
|
||||||
# From the front
|
# From the front
|
||||||
array[0] #=> 1
|
array[0] #=> 1
|
||||||
|
array.first #=> 1
|
||||||
array[12] #=> nil
|
array[12] #=> nil
|
||||||
|
|
||||||
# Like arithmetic, [var] access
|
# Like arithmetic, [var] access
|
||||||
@@ -165,6 +166,7 @@ array.[] 12 #=> nil
|
|||||||
|
|
||||||
# From the end
|
# From the end
|
||||||
array[-1] #=> 5
|
array[-1] #=> 5
|
||||||
|
array.last #=> 5
|
||||||
|
|
||||||
# With a start index and length
|
# With a start index and length
|
||||||
array[2, 3] #=> [3, 4, 5]
|
array[2, 3] #=> [3, 4, 5]
|
||||||
|
Reference in New Issue
Block a user