February 6 - Finding Elements Nested Inside Multiple Arrays in Ruby
This coding exercise tests your knowledge of iterating through nested arrays collections and implementing a basic search algorithm.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Add a method to the Array class that searches for a nested array element.

Exercise Description

Build a method that returns an array from a nested array if the second element equals the queried element.

Example

players = [
  [27, 'Jose Altuve'],
  [2,  'Alex Bregman'],
  [1,    'Carlos Correa'],
  [9,    'Marwin Gonzalez'],
  [10, 'Yulieski Gurriel']
]

find_element(players, 'Jose Altuve')
# [27, 'Jose Altuve']

Real World Usage

This exercise has a two-fold purpose:

  1. To work with nested data collections.
  2. So that you can learn about a rarely used Ruby method.

Test Cases

Code File