Ruby - Enumerable - each_with_index

  • + 0 comments

    we can use each_with_index to Iterates through the array while tracking the index with map because you're transforming each element into a new string format and then use drop to skips the first skip formatted entries here is my solution

    def skip_animals(animals, skip)
        animals.each_with_index.map { |animal, index| "#{index}:#{animal}" }.drop(skip)
    end