use array sort results to sort other arrays?

221 views
Skip to first unread message

nmyshkin

unread,
Aug 24, 2018, 5:21:59 PM8/24/18
to Tasker
This has me pretty confused and I'm not sure I can even explain clearly what I want to accomplish.

I have four arrays containing data that "goes together" in the order it exists in the arrays. So, for example, the first item in each array is, respectively:

1. a news story title
2. the URL for an external link to the story
3. a short teaser to the story
4. the publication date of the story

What I'd like to do is sort the publication dates so the most current is at the top, and then apply that sort order to the other three arrays which I will then use to build a file.

I see that arrays can be sorted, but how can I apply the "order" from one sort to other arrays? In other words, if item 3 in the publication date array is the most recent date, how can I make item 3 in each of the other arrays end up as item 1, etc.

Is that even possible? Back in the day I used to do stuff like this in BASIC, but those were multidimensional arrays--and anyway, I couldn't do it now to save my life!

Marta Hintz

unread,
Aug 24, 2018, 5:29:26 PM8/24/18
to Tasker
Super simple with auto tools, harder for plain tasker, but doable. Some one "smarter" can walk you through or you can search, as I have seen it explained online.

Robert Ryan

unread,
Aug 24, 2018, 5:30:12 PM8/24/18
to tas...@googlegroups.com
You can use AutoTools array actions to do this. 


--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Screenshot_20180824-152839_AutoTools.jpg

nmyshkin

unread,
Aug 24, 2018, 6:47:56 PM8/24/18
to Tasker
OK, so I need to search more diligently. I've been looking for examples. AutoTools is not an option so it has to be brute force, some kind of For loop, no doubt.

Robert Ryan

unread,
Aug 24, 2018, 7:44:47 PM8/24/18
to tas...@googlegroups.com
How many items are we we talking about? I'm thinking a recursive merge sort would be easiest and most efficient, but it's still going to be a ton of work. 

It might be easier to write it in Javascript. 

There may also be some Java functions that would help, but none spring immediately to mind. 

--

nmyshkin

unread,
Aug 24, 2018, 8:10:19 PM8/24/18
to Tasker
Probably 10-20 items, depending on the news category. I'm wondering if it might be better to do an IF scan of the pubDates (after I create a string from Tasker that matches the date format) and build the local HTML page of news titles, URLs and teasers based on the match of the date to either today or yesterday. So if the date fits the category then that item (based on the index number of the array) is written to the HTML file as a title-URL-teaser unit. If there is not a match then it's not written and the testing for matches continues until the array has been fully tested.

That would eliminate sorting the array entirely.

Rich D

unread,
Aug 25, 2018, 8:46:57 AM8/25/18
to Tasker Google Groups Post
Having no real programing experience, here is how I would approach this. This task basically adds a numeric tag to all the elements in the array to be sorted then after the sort it uses those tags to sort the other arrays. 

Array Sort (642)
A1: Array Set [ Variable Array:%names Values:two,one,three,five,four Splitter:, ] 
A2: Array Set [ Variable Array:%nums Values:2,1,3,5,4 Splitter:, ] 
A3: For [ Variable:%int Items:1:%nums(#) ] 
A4: Variable Set [ Name:%sort(%int) To:%nums(%int)|%int Recurse Variables:Off Do Maths:Off Append:Off ] 
A5: End For 
A6: Array Process [ Variable Array:%sort Type:Sort Numeric, Integer ] 
A7: For [ Variable:%intn Items:1:%names(#) ] 
A8: Variable Set [ Name:%split To:%sort(%intn) Recurse Variables:Off Do Maths:Off Append:Off ] 
A9: Variable Split [ Name:%split Splitter:| Delete Base:Off ] 
A10: Variable Set [ Name:%new_names(%split2) To:%names(%intn) Recurse Variables:Off Do Maths:Off Append:Off ] 
A11: End For 
A12: Flash [ Text:%new_names() Long:Off ] 



Array_Sort.tsk.xml
Reply all
Reply to author
Forward
0 new messages