Array question- need to check off elements in the array

I have 2 arrays, I’m trying to fill in a table and check off (true false) for tasks.
ie task =[ take out the trash, wash the dishes, mow the lawn]

the other array of user are assigned tasks ;
ie Fred = [ mow the lawn]

I was trying to loop thru the tasks and check if the assigned tasks are included in the array.
(but that not right because it returns true for all tasks)

So, basically I’m not sure how to compare elements from assigned tasks that are not in the list of all tasks.

any suggestions?

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