Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove elements from one NSMutableArray which are contained in another array

I have two arrays, A and B.

How can I remove elements from A, if those elements exist in B?

e.g. Array A:{1,2,3,4,5}, array B:{1,3}

I would like to remove 1 and 3 from array A such that array A only contains 2,4,5 after the operation.

Besides looping, is there any more efficient approach to doing it?

like image 654
hosir Avatar asked Dec 06 '10 10:12

hosir


1 Answers

You have the removeObjectsInArray: method from NSMutableArray. It does what you want.

like image 69
Laurent Etiemble Avatar answered Oct 26 '22 02:10

Laurent Etiemble