AppleScript名:2つの1D Listの共通項を返す v2 |
— Created 2014-11-18 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –aList内に重複項目、bList内に重複項目が存在していた場合に、それが検出される可能性もある set aList to {1, 2, 3, 4, 5} set bList to {0, 1, 2, 4, 5, 6} set aRes to getSameItemsInLists(aList, bList) of me –> {2, 5, 1, 4} on getSameItemsInLists(aList as list, bList as list) –ASオブジェクトをCocoaオブジェクトに変換 set aArray to current application’s NSArray’s arrayWithArray:aList set bArray to current application’s NSArray’s arrayWithArray:bList — まとめる set allSet to current application’s NSMutableSet’s setWithArray:aArray allSet’s addObjectsFromArray:bArray –重複する要素のみ抜き出す set duplicateSet to current application’s NSMutableSet’s setWithArray:aArray duplicateSet’s intersectSet:(current application’s NSSet’s setWithArray:bArray) –重複部分だけを返す set resArray to duplicateSet’s allObjects() set resList to resArray as list return resList end getSameItemsInLists |
More from my site
(Visited 18 times, 1 visits today)