February 5 - Build an Index-Based Array to Hash Converter in Ruby
This coding exercise walks through how to build a method that converts an array to a hash, with the index value of the array elements becoming the hash keys and the values being the array elements.
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
Implement a method that converts an array to a hash with index based keys.
Exercise Description
Build a method that converts an array to a hash, with the index value of the array elements becoming the hash keys and the values being the array elements.
Example Input
["the", "quick", "brown", "fox"]
Example Output
{0=>"the", 1=>"quick", 2=>"brown", 3=>"fox"}
Real World Usage
A common requirement for developers is to be able to switch between data collection types, such as converting arrays into hashes. Additionally, this exercise examines how to properly find the index value for array elements.