AppleScript名:2つの1D Listから重複項目のみ抽出。個別の重複項目のチェックつき |
— Created 2017-12-17 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSCountedSet : a reference to current application’s NSCountedSet set aList to {1, 2, 3, 4, 5} set bList to {0, 1, 2, 4, 5, 6} –それぞれのListに重複項目が存在するかをチェック set aRes1 to returnDuplicatesOnly(aList) of me set bRes1 to returnDuplicatesOnly(bList) of me if {aRes1, bRes1} is not equal to {{}, {}} then return false –aListとbListを連結したListで重複が存在するかをチェック set aArray to current application’s NSArray’s arrayWithArray:aList set bArray to current application’s NSArray’s arrayWithArray:bList set cArray to aArray’s arrayByAddingObjectsFromArray:bArray set cRes to returnDuplicatesOnly(cArray) of me –> {5, 1, 2, 4} on returnDuplicatesOnly(aList as list) set aSet to NSCountedSet’s alloc()’s initWithArray:aList set bList to (aSet’s allObjects()) as list set dupList to {} repeat with i in bList set aRes to (aSet’s countForObject:i) if aRes > 1 then set the end of dupList to (contents of i) end if end repeat return dupList end returnDuplicatesOnly |
More from my site
(Visited 43 times, 1 visits today)