AppleScript名:1Dリスト中の最も近い値を返す |
— Created 2017-11-11 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" –http://piyocast.com/as/archives/4971 property NSArray : a reference to current application’s NSArray set aList to {50, 30, 20, 15, 10, 5, 0} set targNum to retNearestNumInList(7, aList) of me –> 5 set targNum to retNearestNumInList(100, aList) of me –> 50 on retNearestNumInList(aNum, aList as list) set anNSArray to NSArray’s arrayWithArray:aList set bList to (anNSArray’s sortedArrayUsingSelector:"compare:") as list set aPreNum to 0 repeat with i in bList set j to contents of i if j ≥ aNum then exit repeat end if set aPreNum to j end repeat return aPreNum end retNearestNumInList |
More from my site
(Visited 12 times, 1 visits today)