Search code examples
javascriptobjective-carrayssplice

JS splice function to Objective-C


The main goal is well, first. array a will contain more values than array b, a contains a,a,a,b,c,c,d,e and the b contains a,b,b,b,b,c,c,and I want to find the same values from array b in the array a, that would be a,b,b,b,b,c,c...every time find one item, I will link some events...but normally it will find the same value only once, that would be a,b,c...I don't want that.

This is my Js code:

    var a = ['he','you','and','she','me'];
    var b = ['he','and','you','and'];

    for(var i = 0;i < a.length;i++){
       for(var ii = 0; ii < b.length; ii++){
          if(b[ii] == a[i]){
             b.splice(ii,1);
          }
     }

First, look through the items of array b in the array a, I want to remove the first of the double items in the array a, when the array b match with array a, and then look thorough again, then repeat the steps... and I want to convert js code to objective-c, anyone knows how can I do that? Thanks


Solution

  • It's not clear what your splice function should do. But perhaps you could base it on the following snippet:

    NSArray* result = [sourceArray subarrayWithRange:NSMakeRange(2, 1)];