You are viewing a single comment's thread. Return to all comments →
def neg_pos(arr, index) # return the element of the array at the position index from the end of the list arr[-index] end
index
def first_element(arr) # return the first element of the array arr.first end
def last_element(arr) # return the last element of the array arr.last end
def first_n(arr, n) arr.take(n) # return the first n elements of the array end
def drop_n(arr, n) arr.drop(n) # drop the first n elements of the array and return the rest end
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby Array - Index, Part 2
You are viewing a single comment's thread. Return to all comments →
def neg_pos(arr, index) # return the element of the array at the position
index
from the end of the list arr[-index] enddef first_element(arr) # return the first element of the array arr.first end
def last_element(arr) # return the last element of the array arr.last end
def first_n(arr, n) arr.take(n) # return the first n elements of the array end
def drop_n(arr, n) arr.drop(n) # drop the first n elements of the array and return the rest end
evrey thing is given in the syntax all you need is to just observe it