Determine missing item using a filter

I’m having a bit of TW writers block today so thought I’d ask for some help.

I have a TW where I’m keeping an inventory of my trade card collection. The collection consists of a number of sets with each set having a varying number of cards in it. The set is represented by a tiddler and one of its fields entitled issued represents the number of cards that were issued in that set. Each card is represented by a tiddler tagged with the set tiddler. These card tiddlers are titled starting with a number followed by the name of the card (e.g. 1 - Bluebird, 2 - Woodpecker, etc.). The card tiddler only exists if I own that card. For example, if I have a set of 20 and I own all 20, then there would be 20 tiddlers. Otherwise, there would be only the number of tiddlers of the cards I owned.

I want to write a filter such that it would list the number of the cards that are missing. For example, if I have a set of 20 and I’m missing 11-14, the result of the filter would be 11, 12, 13, 14. I’m fairly convinced that this can be done, but I’m having trouble figuring out where to start.

Does anyone have any suggestions? Thanks in advance!

You can use the range operator :

{{{ [range[1],{!!issued}]-[tag{!!title}abs[]]}}}

demo : TiddlyTweaks — Small tweaks for TiddlyWiki

Thanks very much. That’s exactly what I needed. I have had no occasion to use range or abs so they were not in the forefront of my mind.

You’re welcome :slight_smile:

Normally it’s supposed to be used for calculus and I first tough of using a split operator, but it turns out that abs[] will discard any non-numeric character, so it was perfect for this job.

As long as your number is somewhere in the title, it will get the first one and output that. edit: It needs to be at the start of the string. My bad ! Also using add[] keeps the sign, if you ever need it use that instead.

I think you could also use a search operator in a map filter run to discard numbers found in a list of titles but IMO this is more prone to errors and lengthier.

1 Like

I ended up also trying the split operator and got it to work, but it’s much more lengthy and not as elegant as the abs operator.

I definitely need to look at the operators that I’m not familiar with and get to know them. This is a case in point. Thanks again.

1 Like