You are viewing a single comment's thread. Return to all comments →
def end_arr_add(arr, element) # Add element to the end of the Array variable arr and return arr arr.push(element) end
element
arr
def begin_arr_add(arr, element) # Add element to the beginning of the Array variable arr and return arr arr.unshift(element) end
def index_arr_add(arr, index, element) # Add element at position index to the Array variable arr and return arr arr.insert(index, element) end
index
def index_arr_multiple_add(arr, index) # add any two elements to the arr at the index arr.insert(index, 'a', 'b') end
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby Array - Addition
You are viewing a single comment's thread. Return to all comments →
def end_arr_add(arr, element) # Add
element
to the end of the Array variablearr
and returnarr
arr.push(element) enddef begin_arr_add(arr, element) # Add
element
to the beginning of the Array variablearr
and returnarr
arr.unshift(element) enddef index_arr_add(arr, index, element) # Add
element
at positionindex
to the Array variablearr
and returnarr
arr.insert(index, element) enddef index_arr_multiple_add(arr, index) # add any two elements to the arr at the index arr.insert(index, 'a', 'b') end
Try this