This coding exercise tests your knowledge of iterating through nested arrays collections and implementing a basic search algorithm.
Add a method to the
Arrayclass that searches for a nested array element.
Build a method that returns an array from a nested array if the second element equals the queried element.
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:
- To work with nested data collections.
- So that you can learn about a rarely used Ruby method.
Can be found on the solutions branch on github.