AppleScript名:NSCountedSetでNSDictionaryの登場頻度集計 v2 |
— Created 2015-09-14 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRecList to {{aName:"Piyomaru", aFavorite:"Sleeping"}, {aName:"Piyoko", aFavorite:"TV"}, {aName:"Piyomaru", aFavorite:"Sleeping"}} set aCountedList to countEachRecord(aRecList) –> {{aCount:1, aData:{aName:"Piyoko", aFavorite:"TV"}}, {aCount:2, aData:{aName:"Piyomaru", aFavorite:"Sleeping"}}} on countEachRecord(aRecList) set theCountedSet to current application’s NSCountedSet’s |set|() repeat with i in aRecList set j to contents of i (theCountedSet’s addObject:j) end repeat set theEnumerator to theCountedSet’s objectEnumerator() set anArray to current application’s NSMutableArray’s alloc()’s init() repeat set aDict to current application’s NSMutableDictionary’s alloc()’s init() set aValue to theEnumerator’s nextObject() if aValue is missing value then exit repeat set aCount to theCountedSet’s countForObject:aValue aDict’s setObject:aCount forKey:"aCount" aDict’s setObject:aValue forKey:"aData" anArray’s addObject:aDict end repeat return anArray as list of string or string end countEachRecord |
More from my site
(Visited 39 times, 1 visits today)