3 개의 배열 중에서 가장 긴 (가장 높은 수) 배열을 찾으려면 어떻게합니까?가장 많은 수의 배열 찾으십시오.
배경 : I 매칭 함수는 잘 작동해야
- 사용 환경 containg 부울 값을 갖는 세 개의 사전, 물품은 세 가지 태그 카테고리를 가지고, 기능 검사 거세한 숫양 태그 A는, 태그 B가 켜져 사전 (A)에 온 사전 B 등의
이제 요구 사항은 태그 A의 N 항목, 태그 B에서 N 항목,있을 수 있다는 것이다 등
그래서 태그의 세 배열의 각각 다른 길이 될 수 있다는 것을, 가장 쉬운 내가 생각할 수있는 방법은 ArrayA, ArrayB 및 ArrayC에서 가장 긴 배열 (대부분의 항목 포함)을 찾는 것입니다.
이 내 원래 작업 루프
for (id myArrayElement in storyArray) {
NSString *myString = [NSString stringWithString:[myArrayElement industryA]];
NSString *myIssue = [NSString stringWithString:[myArrayElement issueA]];
NSString *myService = [NSString stringWithString:[myArrayElement serviceA]];
if (
[prefsDictionary valueForKeyPath:[NSString stringWithFormat:@"Industries.%@", myString]] ||
[prefsDictionary valueForKeyPath:[NSString stringWithFormat:@"Issues.%@", myIssueElement]] ||
[prefsDictionary valueForKeyPath:[NSString stringWithFormat:@"Services.%@", myService]]
) {
// One of the story's tags matches a key in one of the corresponding dictionaries
// Look up what this preference is set to
NSString *keyvalue = [[prefsDictionary valueForKey:@"Industries"] valueForKey:myString];
NSString *Issuesvalue = [[prefsDictionary valueForKey:@"Issues"] valueForKey:myIssueElement];
NSString *Servicevalue = [[prefsDictionary valueForKey:@"Services"] valueForKey:myService];
if (
[keyvalue isEqualToString:@"1"] ||
[Issuesvalue isEqualToString:@"1"] ||
[Servicevalue isEqualToString:@"1"]
) {
// It's a match, add the story
[self.favList addObject:myArrayElement];
}
} // prefsDictionary End if
사람이 멋진을 가지고하지 않는 한 나는 3 개 개의 입력이 길이의 배열이 될 수있는이 작업을 수행하는 가장 좋은 방법을
for (id myArrayElement in delegate.storyArray) {
NSArray *industyArr = [[myArrayElement industryA] componentsSeparatedByString:@"|"];
NSArray *issueArr = [[myArrayElement issueA] componentsSeparatedByString:@"|"];
NSArray *serviceArr = [[myArrayElement serviceA] componentsSeparatedByString:@"|"];
// We need to find longest array
// Pad the shorter arrays, or use if ([array count] >= 4) {id obj = [scores objectAtIndex:3];}
// Then loop using the largest array length
for (loop longest array length) {
// get nth entry in industyArr... thisIndustry
// get nth entry in issueArr... thisIssue
// get nth entry in serviceArr... thisService
if (
[prefsDictionary valueForKeyPath:[NSString stringWithFormat:@"Industries.%@", thisIndustry]] ||
[prefsDictionary valueForKeyPath:[NSString stringWithFormat:@"Issues.%@", thisIssue]] ||
[prefsDictionary valueForKeyPath:[NSString stringWithFormat:@"Services.%@", thisService]]
) {
// One of the story's tags matches a key in one of the corresponding dictionaries
NSString *keyvalue = [[prefsDictionary valueForKey:@"Industries"] valueForKey:thisIndustry];
NSString *Issuesvalue = [[prefsDictionary valueForKey:@"Issues"] valueForKey:thisIssue];
NSString *Servicevalue = [[prefsDictionary valueForKey:@"Services"] valueForKey:thisService];
if (
[keyvalue isEqualToString:@"1"] ||
[Issuesvalue isEqualToString:@"1"] ||
[Servicevalue isEqualToString:@"1"]
) {
// It's a match, add the story
[self.favList addObject:myArrayElement];
// EXIT THE INNER LOOP NOW WE HAVE A MATCH
}
} // prefsDictionary End if
} // End myIssueElement for
} // End myArrayElement for
되어 생각하고 있습니다 아이디어 ...
'[arrayX count]'는 배열에있는 원소의 수를 알려주기 때문에 찾고있는 것을 분명히 놓치고 있습니다. –
죄송합니다 - 질문을 더 잘 이해하려고합니다. 기사 컬렉션을 검색하여 사용자 태그로 태그가 지정된 것을 찾으십니까? – nielsbot
@neilsbot 배열 중에서 가장 긴 배열을 찾고 싶었습니다. 그러면 내 논리가 작동합니다. 나는 코드 덩어리가 누군가에게 유용 할 수 있으며, 게시 된 동안 누군가가 할 수있는 말을 할 수 있습니다 ... – JulianB