January 16 - Rotate Elements in an Array in Ruby
In this coding exercise we'll walk through how to easily rotate the items inside a Ruby array and change the index values for each element.
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
Build a method that dynamically rotates the indices for each of the values in a Ruby array.
Exercise Description
Build a method that takes two arguments: an array, and the number of indices that the array elements should be rotated.
Sample Use
array_rotation([1, 2, 3], 2) # [3, 1, 2]
Real World Usage
There are many times when you want to quickly rotate the elements in an array. This typically comes up when implementing algorithms that need to have flexible data structures.