Finding out NSArray/NSMutableArray changes' indices

前端 未结 3 1420
陌清茗
陌清茗 2021-01-12 14:44

I have a NSMutableArray oldArray. Now, at one point, this NSMutableArray object gets updated with another NSMutableArray,

3条回答
  •  [愿得一人]
    2021-01-12 15:02

    1. addedArray = newArray ∖ (newArray ∩ oldArray)

             = newArray ∖ ({@"a",@"c",@"d",@"e",@"f",@"h"} ∩ {@"a",@"b",@"d",@"e",@"g"}) 
             = newArray ∖ {@"a",@"d",@"e"}            
             = {@"a",@"c",@"d",@"e",@"f",@"h"} ∖ {@"a",@"d",@"e"}
             = {@"c",@"f",@"h"}             
      
    2. removedArray = oldArray ∖ (oldArray ∩ newArray)

               = oldArray ∖ ({@"a",@"b",@"d",@"e",@"g"} ∩ {@"a",@"c",@"d",@"e",@"f",@"h"})
               = oldArray ∖ {@"a",@"d",@"e"}
               = {@"a",@"b",@"d",@"e",@"g"} ∖ {@"a",@"d",@"e"}
               = {@"b",@"g"}
      

    To find intersections of array, you can view the following SO post: Finding Intersection of NSMutableArrays

提交回复
热议问题