— Created 2019-05-27 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set aList to {3, 2, 1, 7, 6, 4}
set bList to {1, 2, 3, 4, 6, 7}
set a1Res to checkAllItemsAreSame(aList, bList) of me
–> true (配列要素の登場順序が変わっていても要素はすべて同じ)
set aList to {3, 2, 1, 7, 6}
set bList to {1, 2, 3, 4, 6, 7}
set a2Res to checkAllItemsAreSame(aList, bList) of me
–> addItems:{4}, minusItems:{}}–配列要素に過不足があった
–1D List同士の全要素が(登場順序が変更になっていても)同じかどうかをチェック
on checkAllItemsAreSame(aList, bList)
set dRes to getDiffBetweenLists(aList, bList) of me
set ddRes to (dRes is equal to {addItems:{}, minusItems:{}}) as boolean
if ddRes = true then
return true
else
return dRes
end if
end checkAllItemsAreSame
–1D List同士のdiffを検出
on getDiffBetweenLists(aArray as list, bArray as list)
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)
–重複部分を削除する
allSet’s minusSet:duplicateSet
set resArray to (allSet’s allObjects()) as list
set aSet to current application’s NSMutableSet’s setWithArray:aArray
set bSet to current application’s NSMutableSet’s setWithArray:resArray
aSet’s intersectSet:bSet –積集合
set addRes to aSet’s allObjects() as list
set cSet to current application’s NSMutableSet’s setWithArray:bArray
cSet’s intersectSet:bSet –積集合
set minusRes to cSet’s allObjects() as list
return {addItems:minusRes, minusItems:addRes}
end getDiffBetweenLists