Skip to content

Instantly share code, notes, and snippets.

@benhowdle89
Created April 25, 2014 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhowdle89/11296338 to your computer and use it in GitHub Desktop.
Save benhowdle89/11296338 to your computer and use it in GitHub Desktop.
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