This coding exercise examines how to iterate through the same array a variable number of times and return a collection that contains the full set of elements that were looped through.
Build a method that replicates Ruby’s
cycle method and iterates through an array a variable number of times, and have the method return an array that contains the full set of elements that were iterated through.
cloned_cycle([1, 2, 3], 3) # [1, 2, 3, 1, 2, 3, 1, 2, 3]
Real World Usage
Understanding how arrays work in Ruby is key to working with data collections, which is one of the most fundamental requirements of data-driven applications. This exercise will help you learn how to work with nested collections, add elements to an array, and override the basic looping functionality provided by collections.
Can be found on the solutions branch on github.