0

I have two array, array A has 4 elements and array B has 10 elements. How to compare this two array together to find out whether array A has values that contains in array B.

Here is the codes.

   for(int i = 0; i <= deepsightSig.count; i++){
    for(int p = 0; p <= feeds.count; i++){


        if(feeds[i] == deepsightSig[i]){

            badIPCount++;


        }
        else
            goodIPCount++;

    }


}
7
  • You just need to check arrayB contain object from Array A Commented Nov 20, 2015 at 8:54
  • Do the arrays contain the same type of objects? Would equivalent objects compare as equal when sent the isEqual: message? Commented Nov 20, 2015 at 8:54
  • Array A and Array B contains same types of objects but different number of elements. for example array A has 4 elements but array B has 10 elements. Commented Nov 20, 2015 at 8:55
  • Please show me the updated codes i listed. Thank You Commented Nov 20, 2015 at 8:57
  • I post answer with two array.So Please Check it Commented Nov 20, 2015 at 8:58

1 Answer 1

8
NSMutableSet* set1 = [NSMutableSet setWithArray:array1];
NSMutableSet* set2 = [NSMutableSet setWithArray:array2];
[set1 intersectSet:set2]; //this will give you only the obejcts that are in both sets

NSArray* result = [set1 allObjects];

if result.count is greater than one it means array A have values that are in array B.

Sign up to request clarification or add additional context in comments.

1 Comment

I love sets, they will change your life

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.