Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NSInteger count = [timelineData count];
for (NSInteger index = (count - 1); index >= 0; index--) {
NSMutableDictionary *tweet = timelineData[index];
if (tweet[@"retweeted_status"]) {
[timelineData removeObjectAtIndex:index];
} else {
NSMutableDictionary *userObject = [tweet[@"user"] mutableCopy];
int fav_count = tweet[@"favorite_count"];
int rt_count = tweet[@"retweet_count"];
int follower_count = userObject[@"followers_count"];
float score = (((float)fav_count + (float)rt_count) / (float)follower_count) * 1000;
[timelineData[index] setObject:[NSNumber numberWithFloat:score] forKey:@"score"];
}
}
NSMutableArray *sortedArray;
sortedArray = [timelineData sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
float firstScore = [a[@"score"] floatValue];
float secondScore = [b[@"score"] floatValue];
if (firstScore > secondScore) {
return (NSComparisonResult)NSOrderedAscending;
}
if (firstScore < secondScore) {
return (NSComparisonResult)NSOrderedDescending;
}
return (NSComparisonResult)NSOrderedSame;
}];
_tweets = [sortedArray subarrayWithRange:NSMakeRange(0, 10)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment