Sorting Deep Nested Arrays
Brahmanathswami
brahma at hindu.org
Sun Dec 8 23:47:06 EST 2013
I followed Ender Nafi's lead on this. I agree.
"Often, the simplest methods are the most reliable one."
My head starts to spin with the arrays get too deep. It's so easy to
load them up , but then getting it back out!
so Ender's idea was to "get out of the array" good!
I used tried and true verbose brick by brick expressions to get into a
list instead of yet another array.
# For a listing we just need to get the data out into a simple line-tab
delimited variable
# to sort it properly the array keys are not sortable
put tRow["start_time"] & tab into tTaskLine
put tRow["task"] & tab after tTaskLine
put tRow["budget"] & tab after tTaskLine
put tRow["description"] & tab after tTaskLine
put tRow["budget"] & tab after tTaskLine
put tRow["amount"] after tTaskLine
# we are switching to line based delivery so we need to wipes
CR's in the description now
replace cr with " " in tTaskLine # one space
put tTaskLine & cr after tLongReport
end repeat
set the itemdel to tab
sort tLongReport descending by item 1 of each
put tLongReport into gData["allTasksReport"]
then in my revIgniter output view I used this:
<?
put empty into tBuf
put gData["allTasksReport"] into tList
repeat for each line tEntry in tList
set the itemdel to tab
put "<tr><td class='border'>"& (item 1 of tEntry) &"</td><td
class='border'>"& (item 2 of tEntry) &"</td><td class='border'>"&( item
3 of tEntry) &"</td><td class='description border'>" & (item 4 of
tEntry) &"</td><td class='border'>"& (item 5 of tEntry) &"</td><td
class='aRight border'>"& (item 6 of tEntry) &"</td></tr>" after tBuf
end repeat
return tBuf
?>
OK, so maybe a few more lines of code and not as "cool" as arrays, but
it's transparent and de-buggable.
And for just a few fields, very small amount or data... where the
content is short text strings and numbers, it hardly more code doing
operations on tab del lines vs doing repeat loops on array keys and then
sorting the keys and output the array on another loop iteration over
sorted keys: you end up with almost as much code and it's very dense
OTOH just the gData array in RevIgniter is really fun.
Swasti Astu, Be Well!
Brahmanathaswami
Kauai's Hindu Monastery
www.HimalayanAcademy.com
Robert Sneidar wrote:
> Often, the simplest methods are the most reliable ones.
> > How about combining the array into a temporary variable,
> > then sort it by the*item* (formerly*key*) you want,
> > then construct the tBuf?
More information about the use-livecode
mailing list