samedi 25 juin 2016
Finding Most Repeated Object In Array For Group of Objects
Yea, so the title isn't doing the greatest of jobs for me, I get it, but couldn't think of a good way to summarize it briefly.
I have an Object from Parse that has about 8 rows in it. Within each row there is an array, containing days of the week. When someone votes for one day for that particular row, it adds that day to the array for that row.
So, the Object with 8 days may have 1 row with just Sunday in the array, while another may have 2 of every day of the week, and 3 for Sunday.
What I want to do is to sort through that array, finding the row that has the most of each day. Like row 1 has 3 Sundays, row 2 has 2 Sundays, so it would say row 1 is the one that should take place on Sunday. Basically just creating a best fit schedule. I have used this inside the cellForRowAtIndexPath code, and I would greatly appreciate some help in how I could go through this and make a tableview sorted by day using this as the guide for it:
NSArray *yourArrayhere = object[@"DatesSuggested"];
if (yourArrayhere == NULL) {
cell.text = @"No votes have been cast for this activity yet.";
}
else {
NSCountedSet *setOfObjects = [[NSCountedSet alloc] initWithArray:yourArrayhere];
//Declaration of objects
NSString *mostOccurringObject = @"";
NSUInteger highestCount = 0;
//Iterate in set to find highest count for a object
for (NSString *strObject in setOfObjects)
{
NSUInteger tempCount = [setOfObjects countForObject:strObject];
if (tempCount > highestCount)
{
highestCount = tempCount;
mostOccurringObject = strObject;
}
}
cell.text = [@"Based on popular vote, the suggested day for this activity is " stringByAppendingString:mostOccurringObject];
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire