set example to {"a", "b", "c", "d", "e"}
set x to 3
set new_list to repeatListItems(example, x)
on repeatListItems(originalList, x)
set newList to {}
repeat with thisItem in originalList
set thisItem to thisItem's contents -- Resolve the reference.
repeat x times
set end of newList to thisItem
end repeat
end repeat
return newList
end repeatListItems
In reading and learning about Applescript, I often see Nigel’s script written as follows:
set example to {"a", "b", "c", "d", "e"}
set x to 3
set new_list to repeatListItems(example, x)
on repeatListItems(originalList, x)
set newList to {}
repeat with i from 1 to (count originalList)
set thisItem to (item i of originalList)
repeat x times
set end of newList to thisItem
end repeat
end repeat
return newList
end repeatListItems
Is one method or the other preferable in some way or is this simply a matter of style? Thanks.
In this particular case, it’s simply what occurred to me as I was writing the script. Either form will do here. If the original list contained hundreds or thousands of items, I might do a bit more experimenting to see if either was more conducive to being sped up!