ruby - How do I display both the first and last elements of an array? -
i want return first , last elements of array.
def first_and_last(a) a.first a.last end
but it's displays last element , when put plus sign adds elements. want print this[1,3]. suggestions?
another way:
['cat', 'dog', 'pig'].values_at(0,-1) #=> ["cat", "pig"]
Comments
Post a Comment