Ruby Array - Index, Part 1

Sort by

recency

|

37 Discussions

|

  • + 0 comments
        arr[index]
    
        arr[start_pos..end_pos]
    
        arr[start_pos...end_pos]
    
        arr[start_pos,length]
    
  • + 0 comments

    It is one of the best way to explore and you can gain a lot of knowledge through this site Fairexch9 login

  • + 0 comments

    you can get the latest quiz by logging in. The test is in English and is based on Norwegian culture and history. The test is a bit tricky, but the answers are all correct. You can get the latest Telenor quiz today from our website. These answers are mostly about general knowledge and education.

  • + 0 comments

    How to index array in Ruby? https://bit.ly/3EZfFt5

  • + 0 comments
    def element_at(arr, index)
        # return the element of the Array variable `arr` at the position `index`
        # arr.at(index) # or
        # arr[index]
        return arr[index]
    end
    
    def inclusive_range(arr, start_pos, end_pos)
        # return the elements of the Array variable `arr` between the start_pos and end_pos (both inclusive)
        return arr[start_pos..end_pos]
    end
    
    def non_inclusive_range(arr, start_pos, end_pos)
        # return the elements of the Array variable `arr`, start_pos inclusive and end_pos exclusive
        return arr[start_pos...end_pos]
    end
    
    def start_and_length(arr, start_pos, length)
        # return `length` elements of the Array variable `arr` starting from `start_pos`
        return arr[start_pos, length]
    end