Generating a Hash from Two Arrays in Ruby

0
2405

This coding exercise examines how to build a method that takes in two arrays and outputs a hash where one array makes up the keys and the other array makes up the values.

Summary

Build a Hash generating method that creates a key/value Hash based on the data from two arrays.

Exercise File

Code File

Exercise Description

Build a method that takes in two arrays as arguments and returns a hash where one array makes up the keys and the other array makes up the values.

Sample Input

arr_1 = ['title', 'description', 'rating']
arr_2 = ['Fountainhead', 'Novel about unique perspectives', 5]

Sample Output

{"title"=>"Fountainhead", "description"=>"Novel about unique perspectives", "rating"=>5}

Real World Usage

A common practice in Ruby development is combining and mapping collections and converting input data into various data structures. This skill can be utilized when performing tasks such as mapping a set of headers to data values, much like you’d do when rendering CSV data in a web application.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here