Build an Index-Based Array to Hash Converter in Ruby

0
836

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.

Summary

Implement a method that converts an array to a hash with index based keys.

Exercise File

Code File

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.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here