Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
joetesta
Level 10

Documentation semantic question

I'm looking into array sorting of Associative Arrays and when I arrived at this page https://sdkdocs.roku.com/display/sdkdoc/ifArraySort
I became concerned that it says it's implemented by roArray but not by roAssociativeArray.
But it actually does have the function for sorting AAs - should the page be updated to say that this is also implemented by roAssociativeArray?
thanks in advance.
aspiring
0 Kudos
3 Replies
Roku Employee
Roku Employee

Re: Documentation semantic question

"joetesta" wrote:
I'm looking into array sorting of Associative Arrays and when I arrived at this page https://sdkdocs.roku.com/display/sdkdoc/ifArraySort
I became concerned that it says it's implemented by roArray but not by roAssociativeArray.
But it actually does have the function for sorting AAs - should the page be updated to say that this is also implemented by roAssociativeArray?
thanks in advance.


Arrays are sortable, associative arrays are not.
You can sort an array *of* associative arrays, but you are modifying the array itself, i.e. the order of items, and not modifying the array item values themselves.
0 Kudos
EnTerr
Level 8

Re: Documentation semantic question

When people speak - informally - about "sorting of dictionaries (assoc.arrays)", in my experience we tend to mean accessing/enumerating the dictionary in particular order - either by order of keys or order of values. 

Now, roAA have .keys() method that returns array of the keys, pre-sorted.
OTOH, there is no .values() method...

PS. I thought i'll illustrate,
'for keys'
for each key in myAA.keys(): 'already sorted, haha!'
   do_the_due(key, myAA[key])
next

'for values - invert the dictionary'
inv_aa = {}
for each key in myAA:
   val = myAA[key]
   bucket = inv_aa[val]: if bucket=invalid then bucket = []: inv_aa[val] = bucket
   bucket.push(key)
next
for each vals in inv_aa:
   for each val in vals:
       do_the_due(vals[val], val)
   next
next
0 Kudos
joetesta
Level 10

Re: Documentation semantic question

You're right, I was hoping to sort on the keys and twisting my brain trying to figure out how to change my Associative Array so that the keys became sortable fields.
Ha - thanks again, yesterday I found the `.keys()` solution you'd posted earlier EnTerr, you are the best!!
-Joe
aspiring
0 Kudos