nsstring - Objective-C: How to find the most common string in an array? -


i have array of strings online database trying determine commonly used word. values inside arrays vary want check common words of whatever collection or words i'm using. if theoretically had array of following...

nsarray *stringarray = [nsarray arraywithobjects:@"duck", @"duck", @"duck", @"duck", @"goose"]; 

how iterate through array determine common string, "duck"?

simplest way nscountedset:

nscountedset* stringset = [[nscountedset alloc] initwitharray:strings]; nsstring* mostcommon = nil; nsuinteger highestcount = 0;  for(nsstring* string in stringset) {     nsuinteger count = [stringset countforobject:string];     if(count > highestcount) {         highestcount = count;         mostcommon = string;     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -