February 7 - Cloning the Cycle Method in Ruby to Repeatedly Go Through an Array
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.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Replicate Ruby's
cycle
method.
Exercise Description
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.
Example
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.