Tricky Filter Question

115 views
Skip to first unread message

scourfie...@gmail.com

unread,
Feb 14, 2021, 7:25:57 AM2/14/21
to TiddlyWiki
Hey all

I've got a situation where I have two lists. List A and List B. I've specified some dummy info below:

A: Alpha Beta Gamma Delta
(this will change by user input, but for this example:) Alpha Gamma

I want to write a filter to apply to List A where if any item does not also appear on List B (i.e. in this case Beta and Delta are missing), it is overwritten by the immediately subsequent value in List A, except the very last item in List A which is remains in place to act as a default value if no subsequent value can be found.

So in this example the filtered version of List A would output as: Alpha Gamma Gamma Delta, because Beta was not present in List B so it is replaced by the next value of Gamma, and Delta remains because it is at the very end.

My question is, is there a way to do this with a static filter expression? I'm sure I could make something with action-listops widgets that would do the job when they were activated, but ideally I want something that updates automatically whenever the user changes List B.

Any help anyone could provide would be much appreciated.

Thanks
Joseph

Charlie Veniot

unread,
Feb 14, 2021, 10:26:34 PM2/14/21
to TiddlyWiki
Silly question:  If A was : Alpha Beta Alternative Delta, and B was still "Alpha Gamma", what should the final result be?

scourfie...@gmail.com

unread,
Feb 15, 2021, 4:11:56 AM2/15/21
to TiddlyWiki
Ideally "Alternative" would just be overriden by Delta, since it doesn't appear in List B

Charlie Veniot

unread,
Feb 15, 2021, 8:40:41 AM2/15/21
to TiddlyWiki
Just using pseudocode to understand the process:

bCount = the number of entries in B
aCount = the number of entries in A minus 1 (i.e. minus the last entry which the process always leaves as is, so the last one is ignored)
aLastEntry = the last entry 
Result will be the final list

LoopRangeEnd = aCount

<!-- this is the main process -->
Loop, setting nIndex from 1 to LoopRangeEnd (in steps of 1)
If item nIndex from A exists in B
  Then add item nIndex from A to Result
Otherwise 
     If nIndex > bCount
       Then add the last item from A to Result
     Otherwise
        Then add item nIndex from B to result

<-- after the main process, tack on the last entry from A -->
Finally, add the last item from A to result

Let me know if that makes sense.  If it does, I think I can do that.

Charlie Veniot

unread,
Feb 15, 2021, 11:59:46 AM2/15/21
to TiddlyWiki
Screenshots below for convenience.

Here you go:  Tricky Filter for Joseph

The tiddler in view mode:
Screenshot 2021-02-15 at 12.53.54 PM.png

The tiddler in edit mode:
Screenshot 2021-02-15 at 12.54.09 PM.png

Reply all
Reply to author
Forward
0 new messages