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

Linux vanilla kernel on QEMU and networking with eth0 -

rdbms - what exactly the undo information lives in oracle? -

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