Remove subset from array

Dick Kriesel dick.kriesel at mail.com
Mon Sep 17 16:56:32 EDT 2007


On 9/17/07 7:40 AM, "Mark Schonewille" <m.schonewille at economy-x-talk.com>
wrote:

> We have the intersect and union commands to manipulate arrays. I
> would like to be able to remove the element of one array from another
> array. E.g. if a,b,c is on array 1 and a,b,c,d,e,f is in array 2, I
> would like to remove a,b,c from array 2 without using a repeat loop.
> 
> Did I miss something and is this possible already, or should I post
> an enhancement request? What would be a good name for such a command,
> if there isn't any yet?

Without a new command or function, the repeat loop is essential, I think.

A quick check of Wikipedia suggests several candidate names:
  relativeComplement
  setTheoreticDifference
  complement
  setDifference
  difference
  setDiff
  diff

See <http://en.wikipedia.org/wiki/Complement_%28set_theory%29>.

Here's what I use:

on set_differenceFromArrays @tArray,pArray,pCaseSensitive
  local tKey
  set the casesensitive to (pCaseSensitive is "true")
  repeat for each key tKey in pArray
    delete variable tArray[tKey]
  end repeat
  delete variable tArray[empty]
end set_differenceFromArrays

Command set_differenceFromLists uses a similar repeat loop.
 
-- Dick





More information about the use-livecode mailing list