In this coding exercise we’ll walk through how to rebuild Ruby’s include? method to see if a value exists inside of an array.
include?method and add a method to the
Arrayclass that checks to see if a value exists within an array.
In order to properly pass this coding exercise you’ll need to open up Ruby’s
Array class and add a method called
does_it_have? that takes in an argument and then have the method return
false depending on whether the element passed in as the method argument is included in the array or not.
arr = [2, 5, 100, 4] arr.does_it_have? 5 # true arr.does_it_have? 20 # false
Real World Usage
It’s important to understand how Ruby’s
Array class operates and this exercise you’ll learn how to properly loop through a collection and return different values based on the method’s input.
Can be found on the solutions branch on github.