I’ve got two arrays of Tasks – created and assigned.
I want to remove all assigned tasks from the array of created tasks.
Here’s my working, but messy, code:
@assigned_tasks = @user.assigned_tasks
@created_tasks = @user.created_tasks
#Do not show created tasks assigned to self
@created_not_doing_tasks = Array.new
@created_tasks.each do |task|
unless @assigned_tasks.include?(task)
@created_not_doing_tasks << task
end
end
I’m sure there’s a better way. What is it?
Thanks 🙂
You can subtract arrays in Ruby:
See the Array documentation.