AppleScript名:2D Listをアイテム数でフィルタリングする |
— Created 2018-04-09 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {{"1"}, {"2", "2"}, {"3", "3", "3"}, {"4", "4", "4", "4"}, {"5", "5", "5", "5", "5"}, {"6", "6", "6", "6", "6", "6"}, {"7", "7", "7", "7", "7", "7", "7"}, {"8", "8", "8", "8", "8", "8", "8", "8"}} set minItemNum to 7 set itemRes1 to retFilterItemMinNum(aList, minItemNum) of me –> {{"7", "7", "7", "7", "7", "7", "7"}, {"8", "8", "8", "8", "8", "8", "8", "8"}} set itemRes2 to retFilterItemEquNum(aList, minItemNum) of me –> {{"7", "7", "7", "7", "7", "7", "7"}} set itemRes3 to retFilterItemMaxNum(aList, minItemNum) of me –> {{"1"}, {"2", "2"}, {"3", "3", "3"}, {"4", "4", "4", "4"}, {"5", "5", "5", "5", "5"}, {"6", "6", "6", "6", "6", "6"}, {"7", "7", "7", "7", "7", "7", "7"}} on retFilterItemMinNum(aList, minItemNum) set anArray to current application’s NSMutableArray’s arrayWithArray:aList set predStr to "SELF[SIZE] >= " & (minItemNum as string) set aPredicate to current application’s NSPredicate’s predicateWithFormat:predStr set t2Array to (anArray’s filteredArrayUsingPredicate:aPredicate) as list return t2Array end retFilterItemMinNum on retFilterItemEquNum(aList, minItemNum) set anArray to current application’s NSMutableArray’s arrayWithArray:aList set predStr to "SELF[SIZE] = " & (minItemNum as string) set aPredicate to current application’s NSPredicate’s predicateWithFormat:predStr set t2Array to (anArray’s filteredArrayUsingPredicate:aPredicate) as list return t2Array end retFilterItemEquNum on retFilterItemMaxNum(aList, minItemNum) set anArray to current application’s NSMutableArray’s arrayWithArray:aList set predStr to "SELF[SIZE] <= " & (minItemNum as string) set aPredicate to current application’s NSPredicate’s predicateWithFormat:predStr set t2Array to (anArray’s filteredArrayUsingPredicate:aPredicate) as list return t2Array end retFilterItemMaxNum |
More from my site
(Visited 40 times, 1 visits today)