Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - Remove items belonging to array B from array A

I'm starting to play with arrays, but i'm stuck with something that seems yet very simple...
I'm trying to remove x elements belonging to one array from another array.
I've looked at this but .... blocked : Deleting items from an array requires multiple passes to remove them all

a = ["1","2","3","4","5","6"]
b = ["1","3"]
c = a.reject { |i| i =~ /b/ }

Well, i'm a bit lot here, thanks!

like image 334
Laurent Avatar asked Sep 10 '25 07:09

Laurent


1 Answers

a = ["1","2","3","4","5","6"]
b = ["1","3"]
c = a - b

same as

c = a.reject{ |e| b.include? e }
like image 146
fl00r Avatar answered Sep 12 '25 23:09

fl00r