AppleScript名:1D List中の最頻出項目を抽出する |
— Created 2016-11-15 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {"positive", "negative", "positive", "positive", "positive"} set bList to countItemsByItsAppearance(aList) of me –> {{theName:"positive", numberOfTimes:4}, {theName:"negative", numberOfTimes:1}} set aRes to theName of contents of first item of bList –> "positive" on countItemsByItsAppearance(aList) set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList set bArray to current application’s NSMutableArray’s array() set theEnumerator to aSet’s objectEnumerator() repeat set aValue to theEnumerator’s nextObject() if aValue is missing value then exit repeat bArray’s addObject:(current application’s NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{"theName", "numberOfTimes"}) end repeat –出現回数(numberOfTimes)で降順ソート set theDesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"numberOfTimes" ascending:false bArray’s sortUsingDescriptors:{theDesc} return bArray as list end countItemsByItsAppearance |
More from my site
(Visited 190 times, 1 visits today)