looking for a smart approach to "sort" an array

Mike Bonner bonnmike at gmail.com
Fri May 5 11:46:58 CEST 2017


It might be easiest to just have a single separate key that contains the
user sorted list, then use the data of that key itself to access the rest
of the array.

So if you have 5 keys, word1,word2,word3,word4,word5, but the user orders
them in reverse, your sorted words single key would contain
word5
word4
word3
word2
word1

Then to get everything back out in the right order one could use a repeat
for each line repeat loop on that key like so.

repeat for each line tKey in myArrayA["sortedWords"]
    -- do whatever with each one myArrayA[tKey].....
end repeat

On Fri, May 5, 2017 at 3:30 AM, Tiemo Hollmann TB via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Hello,
>
> I have a list field of words and a correspondent array with the words of
> the
> field as the keys plus some data per key. I can store the array in a file,
> read it later from file and rebuild the list of words from the keys of the
> array. Up to now, I had this list of words alphabetically sorted. So it was
> easy, when reloading the array to sort the list always alphabetically to
> refresh the visible list in the field.
>
> The user can also create a custom sequence of the words in the field by
> drag
> and drop the lines in individual order. Now I am looking for a smart
> approach to keep the same sort order in the correspondent array. I need the
> custom sort order of the words in case I reload the array later from file
> to
> get the same sequence of words as the user has sorted them, after
> extracting
> the words from the array. The key of the array has to keep the words from
> the list for accessing the data in the array.
>
> As far as I see it, I have to add an additional item to the array data,
> storing the sort sequence of the keys, while the user creates his custom
> sequence of the words in the list field and keeping this number always
> synchronous to the line number of the fields list. So I could use this
> "sort
> sequence number" from the array to rebuild the same sort of the words when
> extracting the words from the array.
>
> Would this be the best approach to keep the sort sequence of the words
> stored with the array, or do you see an easier more straight forward
> approach to keep the array "synchronous sorted" which I don't see right
> now?
>
> Thanks for your input
>
> Tiemo
>
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


More information about the use-livecode mailing list