Just for learning purposes, I wrote a shortcut that calls a recursive shortcut that returns the factorial of a number. The learning part for me was the recursion.
I wanted an example of a recursive handler that manipulated text, and Google AI provided the following:
set theText to "macOS"
set reversedText to reverseText(theText)
on reverseText(theText)
if (length of theText) ≤ 1 then
return theText
else
return (last character of theText) & my reverseText(text 1 thru -2 of theText)
end if
end reverseText
The calling shortcut of the shortcut equivalent is:
Continuing on with my learning, I wanted to write a shortcut that recursively gets all folders in a source folder. The following worked but is abysmally slow with even a moderately-sized folder. I don’t know if that’s a result of the repeat loop that removes files or if there’s some error in the recursion.