Quantcast
Channel: Array question- need to check off elements in the array
Viewing all articles
Browse latest Browse all 2

Array question- need to check off elements in the array

$
0
0

Hey Joe,

You can use the ‘include?’ method from Ruby. It checks whether a specific item is included in an array or not. See the example below.

tasks = ['take out the trash', 'wash the dishes', 'mow the lawn']
Fred = ['mow the lawn']

tasks.each do |task|
  if Fred.include?(task)
    puts "#{task}: true"
  else
    puts "#{task}: false"
  end
end

In this case, ‘mow the lawn’ would return ‘true’, and the others would return ‘false’.

Hope that helps!

Best,
Bobby the Bot

Read full topic


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images