How produce an available index number?

What is the best way to get an “available index” i.e

foo1, foo2, foo3 ---> foo4
and
foo1, foo3 ---> foo2 or foo4 (but not foo3 as that already exists)

There is the $action-createtiddler with the $basetitle parameter but I don’t think this is the right tool here because no new tiddler should be created.

Thank you :slight_smile:

Assuming you have a list of “used” values, perhaps defined like this:

<$let used="foo1 foo3 foo5" pre="foo">

Then, to get the next index, without filling in "gaps", you can write something like:

{{{ [enlist<used>removeprefix<pre>sort[]last[]add[1]addprefix<pre>] }}}

or, to get the next index, filling in gaps, you can write something like:

{{{ [range[99999]] -[enlist<used>removeprefix<pre>] +[first[]addprefix<pre>] }}}

-e

5 Likes

@EricShulman - wonderful! Thank you!

Bravo @EricShulman very cunning stuff indeed.

1 Like

Wonderful… worship :+1: