Another use of the general swiss army knife Array.reduce – moving any completed items (prefixed with - [x] rather than - [ ]) to the end of the contents of a draft.
Start with some kind of seed value (the ‘accumulator’), and
work through a list, updating the accumulator value step by step.
In this case
The seed value is a JS dictionary object (like an Applescript record, but more flexible), which contains two lists, both initially empty, body:[] and end:[],
the step by step function has the usual two basic arguments – (accumulator, item) - in this case the accumulator is the body+end dictionary and the item is the current line.
It just appends the current line either to body:[] (current position), or to end:[] (bottom of draft).
Here is a reusable function:
from the text of an existing draft
to an updated version of that text (with completed items now at the end).
I’ve added this and executed it. I get the green success banner but the draft is unchanged - completed items do not move. Am I forgetting to turn something on?