We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defelement_at(arr,index)# return the element of the Array variable `arr` at the position `index`# arr.at(index) # or# arr[index]returnarr[index]enddefinclusive_range(arr,start_pos,end_pos)# return the elements of the Array variable `arr` between the start_pos and end_pos (both inclusive)returnarr[start_pos..end_pos]enddefnon_inclusive_range(arr,start_pos,end_pos)# return the elements of the Array variable `arr`, start_pos inclusive and end_pos exclusivereturnarr[start_pos...end_pos]enddefstart_and_length(arr,start_pos,length)# return `length` elements of the Array variable `arr` starting from `start_pos`returnarr[start_pos,length]end
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Ruby Array - Index, Part 1
You are viewing a single comment's thread. Return to all comments →