Ruby Array - Index, Part 2

Sort by

recency

|

49 Discussions

|

  • + 0 comments

    You can solve this Ruby challenge with a few simple lines. Here’s the complete and correct code for the problem:

    def init_array() create and return array with 10 elements (integer) in it [9, 7, 6, 5, 4, 6, 7, 1, 2, 3] end

    def neg_pos(arr, index) return the element of the array at the position index from the end of the list arr[-index] end

    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) return first n elements of the array arr.take(n) end

    def drop_n(arr, n) drop first n elements of the array and return the rest arr.drop(n) end

    This uses Ruby’s built-in methods exactly as shown in the problem description — arr[-index], arr.first, arr.last, arr.take(n), and arr.drop(n). It should pass all the tests on HackerRank.

  • + 0 comments

    How does Ruby Array – Index, Part 2 work in practical coding examples, and just like exploring bin stores in Hawaii, what’s the best way to find value efficiently?

  • + 0 comments

    How does Ruby Array – Index, Part 2 work in practical coding examples, and just like exploring bin stores in Hawaii, what’s the best way to find value efficiently?

  • + 0 comments

    Here is hackerRank Ruby Array - Index, Part 2 solution - https://programmingoneonone.com/hackerrank-ruby-array-index-part-2-problem-solution.html

  • + 0 comments

    I don't understand. If we are not provided with the elements parameter, how are we supposed to be able to write the code for AC repair Austin Texas that will add multiple details to an array? Am I giving it too much thought? Simply put, the question is not specific enough for one to be able to understand.