So I have three different arrays involved here…
I’m looping through golferThreeIcons (NSMutableArray), and I’m trying to take the highest 4 results (golferThreeIcons contains #’s as strings) and store them into the topFourIconsNum (NSMutableArray) and then I plan to store the id of that highest number in the array topFourIconsId (NSMutableArray).
One tricky thing is that golferThreeIcons start out at 99, but I want that to act like zero. So the number 99 should not get added to either of the arrays…
Example:
golferThreeIcons {2,1,5,3,9}
And after the loop went through I want it to show something like this…
topFourIconsId {0,2,3,4} — 0 corresponds to 2 in golferThreeIcons — 2 corresponds to 5 in golfer three icons
topFourIconsNum {2,5,3,9} —-(in any order as long as it corresponds to the top four icons id)
NSMutableArray *topFourIconsId = [NSMutableArray arrayWithObjects: @"0", @"0", @"0", @"0", @"0" ,nil];
NSMutableArray *topFourIconsNum = [NSMutableArray arrayWithObjects: @"0", @"0", @"0", @"0", @"0" ,nil];
int *ids = 0;
for (NSString *s in golferThreeIconCounter) {
if(s != @"0") {
int sint = [s intValue];
int *idn = 0;
for(NSString *n in topFourIconsNum) {
int nint= [n intValue];
if(sint == 99 && nint == 0) {
NSString *idstring = [NSString stringWithFormat:@"%d", ids];
NSString *sintstring = [NSString stringWithFormat:@"%d", sint];
[topFourIconsId replaceObjectAtIndex:idn withObject:idstring];
[topFourIconsNum replaceObjectAtIndex:idn withObject:sintstring];
NSLog(@"IN %@",sintstring);
break;
}
else {
if (sint > nint) {
NSString *idstring = [NSString stringWithFormat:@"%d", ids];
NSString *sintstring = [NSString stringWithFormat:@"%d", sint];
[topFourIconsId replaceObjectAtIndex:idn withObject:idstring];
[topFourIconsNum replaceObjectAtIndex:idn withObject:sintstring];
NSLog(@"IN %@",sintstring);
break;
}
}
idn++;
}
}
ids++;
}
Just a crazy idea
Put your golferThreeIcons in a NSDictionary with the array index as the key and the array value as the value and then sort the keys on their value: