— – Created by: Takaaki Naganoya – Created on: 2025/02/03 — – Copyright © 2025 Piyomaru Software, All Rights Reserved —
use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions
set dList to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
set aRes to my subarraysFrom:(dList) groupedBy:6 gapFilledBy:0 –> {{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 0, 0}}
set bRes to my subarraysFrom:(dList) groupedBy:4 gapFilledBy:0 –> {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}
set cRes to my subarraysFrom:(dList) groupedBy:3 gapFilledBy:0 –> {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}, {16, 0, 0}}
–1D Listの2D LIst化 on subarraysFrom:aList groupedBy:colCount gapFilledBy:gapItem script spd property aList : {} property bList : {} property cList : {} end script copy aList to (aList of spd) –deep copy (Important !!!) set (bList of spd) to {} set (cList of spd) to {} set aLen to length of (aList of spd) set aMod to aLen mod colCount –あらかじめ指定数(groupedBy)の倍数になっていない場合にはgap itemを末尾に足しておく if aMod is not equal to 0 then repeat (colCount – aMod) times set the end of (aList of spd) to gapItem end repeat set aLen to length of (aList of spd) end if –通常処理 repeat with i from 1 to aLen by colCount set (bList of spd) to items i thru (i + colCount – 1) of (aList of spd) set the end of (cList of spd) to (bList of spd) end repeat return (cList of spd) end subarraysFrom:groupedBy:gapFilledBy:
|