简体   繁体   English

JS拼接功能到Objective-C

[英]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. 数组a将包含比数组b更多的值,数组a包含a,a,a,b,c,c,d,e,数组b包含a,b,b,b,b,b,c,c,而我想找到数组a中数组b的相同值,即a,b,b,b,b,c,c ...每次找到一个项目,我都会链接一些事件...但是通常它将找到只有一次相同的值,那将是a,b,c ...我不想要那样。

This is my Js code: 这是我的Js代码:

    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? 首先,浏览一下数组a中数组b的各项,当数组b与数组a匹配时,我想删除数组a中的第一个double项,然后再次仔细查看,然后重复这些步骤。我想将js代码转换为Objective-C,谁知道我该怎么做? Thanks 谢谢

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)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM