mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-23 06:03:07 +03:00
Reverse a list
This commit is contained in:
parent
cae1960ca3
commit
51e3bd21e2
@ -169,8 +169,8 @@ array[-1] #=> 5
|
||||
array[2, 3] #=> [3, 4, 5]
|
||||
|
||||
# Reverse an Array
|
||||
# array = [1,2,3]
|
||||
array.reverse #=> [3,2,1]
|
||||
a=[1,2,3]
|
||||
a[::-1] #=> [3,2,1]
|
||||
|
||||
# Or with a range
|
||||
array[1..3] #=> [2, 3, 4]
|
||||
|
Loading…
Reference in New Issue
Block a user