Probably a pointless question about using sort to search..

Peter Brigham pmbrig at gmail.com
Thu Dec 10 12:47:21 EST 2015


Someone on this list at some point posted an array sorting function that
might be relevant here for some applications. See below.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig

"Why is the alphabet in that order? Is it because of that song?"
                -- Steven Wright


function sortArray @pArray, sortMode
   -- sort the values of an array, returning a numerically-keyed array
   --   whose values increase as the keys increase
   -- call it as follows
   --   put sortArray(tArray) into sortedArray
   -- pArray is referenced to avoid duplicating large arrays in memory
   --    but pArray is not changed by this function
   -- sortMode = {"text"|"textCaseSens"|"numeric"|"dateTime"}
   --    textCaseSens sets caseSensitive to true before sorting by text
   --    if sortMode = empty, defaults to numeric
   -- not sure who wrote this

   if sortMode = empty then put "numeric" into sortMode
   # create a list of the array entry values
   put the keys of pArray into keyList
   repeat for each line k in keyList
      put pArray[k] & cr after valueList
   end repeat
   delete char -1 of valueList
   # sort the list as directed
   switch sortMode
      case "textCaseSens"
         set the casesensitive to true
      case "text"
         sort lines of valueList
         break
      case "numeric"
         sort lines of valueList numeric
         break
      case "dateTime"
         sort lines of valueList dateTime
         break
   end switch
   # transform the sorted list back to a numerically indexed array
   split valueList by return
   return valueList
end sortArray


On Thu, Dec 10, 2015 at 11:36 AM, Bob Sneidar <bobsneidar at iotecdigital.com>
wrote:

> You can get the keys of an array and sort them before accessing them. The
> array itself cannot be sorted, and there would be no benefit to doing so
> that I can see.
>
> Bob S
>
>
> On Dec 9, 2015, at 07:56 , Mike Bonner <bonnmike at gmail.com<mailto:
> bonnmike at gmail.com>> wrote:
>
> I was just thinking how useful sort could be to find things (in an array or
> whatever)
>
> _______________________________________________
> 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