This is a question about how to determine what values are in the array

Asked 2 years ago, Updated 2 years ago, 38 views

I'm just learning rubies and want to check if there are specific values in the array.

For example, [1,2,3,4,5] has 3 but not 6.

In other languages, I used to find things like find and index, but I think ruby also has a method that can be used without going around the repetition door.

array ruby

2022-09-21 16:49

1 Answers

Write include?.

If object is in self, return true or false.

myarr = [1,2,3,4,5]
puts myarr.include? 1
puts myarr.include? 10


2022-09-21 16:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.