的最後一個要素:如何打印如何打印數組的所有元素的第二個元素除權後陣列
ARR=["a","b","c","d","f"]
我想打印CDF
ARR=["cat","dog","horse"]
我想打印馬
在此先感謝
的最後一個要素:如何打印如何打印數組的所有元素的第二個元素除權後陣列
ARR=["a","b","c","d","f"]
我想打印CDF
ARR=["cat","dog","horse"]
我想打印馬
在此先感謝
使用Array#[]
與範圍或Array#drop
arr = ["a","b","c","d","f"]
arr[2..-1]
# => ["c", "d", "f"]
arr.drop(2)
# => ["c", "d", "f"]
arr = ["cat","dog","horse"]
arr[2..-1]
# => ["horse"]
arr.drop(2)
# => ["horse"]
一樣簡單
p ARR[2..-1]
其中2和-1是一個元素的索引。
使用Array#last
方法
arr.last(arr.size - 2)
非常感謝 – Juan 2014-09-13 11:07:09