December 28 - Create an Array Converter Method
This ruby coding exercise tests your ability to convert multiple arrays and the data inside of them. The solution also covers how to effectively work with blocks in Ruby.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Create an array converter method that combines a variable number of arrays of strings and converts all of the elements to integers.

Exercise Description

Given any number of arrays containing strings, such as:

arr_1 = ['1', '5', '9']
arr_2 = ['10', '2', '7', '10']
arr_3 = ['3', '4', '0']

Merge all of the arrays into a single array and convert each of the strings to integers.

Sample Output

[1, 5, 9, 10, 2, 7, 10, 3, 4, 0]

Real World Usage

This is a common requirement when working with API data. Many APIs will send data that contains collections of data, and if you're using JSON APIs the data will be of the string data type, even when it's representing numbers. With this is mind it's important to understand how to combine collections and convert their respective data types so that you can work with the data.

Test Cases

Code File