Questions tagged «array-difference»


2
在Ruby中从另一个数组减去一个数组
我有两个任务数组-创建和分配。我想从创建的任务数组中删除所有分配的任务。这是我的工作代码,但很混乱: @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 我敢肯定有更好的方法。它是什么?谢谢 :-)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.