Page 1 of 3 123>
Topic Options
#73374 - 2003-02-24 08:44 PM RE: arraycomp () UDF by Darren
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Darren,

Thanks very much for contributing the code for the ARRAYCOMP () UDF
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000358

I would like to ask though if you could please remove the space in the TITLE so that it reads

arraycomp()

Thanks again.

Top
#73375 - 2003-02-24 11:04 PM Re: RE: arraycomp () UDF by Darren
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Done
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#73376 - 2003-02-25 01:05 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Darren,

How about adding an optional parameter to return
either matching or non-matching elements ?

I took the freedom to code something for ya
(kinda boring here today [Wink] )



break on

$arr1 = a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
$arr2 = 1,2,3,4,f,g,a,34,42,23,c,z,o,r


"results for arraycomp(); elements that doesn't match:" ? ?
for each $e in arraycomp($arr1$arr2)
    $e ?
next

"results for arraycomp(); matching elements:" ? ?
for each $e in arraycomp($arr1$arr21)
    $e ?
next

get $

;slightly adapted version (not perfect, room for improvement  [Wink]  )

function arraycomp($a1$a2optional $m)
    dim $s$o
    If $m $o = ">" else $o = "=" endif
    for each $n in $a2
        $!=execute("if ascan($$a1,$$n) $o -1
                        $$s = $$s + ' ' + $$n
                    endif
                   "
)
    next
    $arraycomp = split($s)
endfunction


J.

[ 25. February 2003, 13:07: Message edited by: jpols ]
_________________________



Top
#73377 - 2003-02-25 02:25 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
j, remove the linebreak of the execution.

it looks horrible when splitted.
_________________________
!

download KiXnet

Top
#73378 - 2003-02-25 02:34 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I knew I could bring you up on this

 -
_________________________



Top
#73379 - 2003-02-25 02:40 PM Re: RE: arraycomp () UDF by Darren
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Acually, I think it looks good. Nicely structured!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#73380 - 2003-02-25 02:47 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh well Les,

this brings up another thought :

If one calls this udf from a script that has NoVarsInStrings activated it would fail !

Maybe I should recode to get rid of that execute() statement ?
Not good for Golf Score but better for reliability ...

like so :



break on

$arr1 = a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
$arr2 = 1,2,3,4,f,g,a,34,42,23,c,z,o,r

"results for arraycomp(); elements that doesn't match:" ? ?
for each $e in arraycomp($arr1$arr2)
    $e ?
next

"results for arraycomp(); matching elements:" ? ?
for each $e in arraycomp($arr1$arr21)
    $e ?
next

get $

;slightly adapted version (not perfect, room for improvement  [Wink]  )

function arraycomp($a1$a2optional $m)
    dim $s
    If $m
        for each $n in $a2
            if ascan($a1,$n) > -1
                $s = $s + ' ' + $n
            endif
        next
    else
        for each $n in $a2
            if ascan($a1,$n) = -1
                $s = $s + ' ' + $n
            endif
        next
    endif
    $arraycomp = split($s)
endfunction



J.

{edit}Oi Lonk, you forgot to mention that I missed the quotes in implicit array declaration [Wink]

[ 25. February 2003, 15:08: Message edited by: jpols ]
_________________________



Top
#73381 - 2003-02-25 03:18 PM Re: RE: arraycomp () UDF by Darren
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
These produce a blank array value at the start of the returned array?

D
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#73382 - 2003-02-25 03:19 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh yeah !

well spotted ... 1 sec. please

[ 25. February 2003, 15:20: Message edited by: jpols ]
_________________________



Top
#73383 - 2003-02-25 03:22 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
j, eh?
I thought you were the execute-tioner and now you skipped that option [Embarrassed]
_________________________
!

download KiXnet

Top
#73384 - 2003-02-25 03:31 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ok,

I decided to ignore and hate all NoVarsInStrings - Users from now on to eternity (Just like Jens always flames on Goto) and recoded the function to both strip first blank and get me a good golf score [Big Grin]



function arraycomp($a1$a2optional $m)
    dim $s$o
    If $m $o = ">" else $o = "=" endif
    for each $n in $a2
        $!=execute("if ascan($$a1,$$n)$o-1 $$s=$$s+' '+$$n endif ")
    next
    $arraycomp = splitsubstr($s,2,len($s)) )
endfunction



J.

-----------------

the execute()-tioner
(That was once my sig. in the days of deciding what strategy to implement for KixForms Event trapping [Wink] )
_________________________



Top
#73385 - 2003-02-25 03:41 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mm...
actually, the execution line was not so good way to do simple thingie...

code:
function arraycomp($a1, $a2, optional $m)
dim $s
for each $n in $a2
if (ascan($a1,$n)>-1 and $m) or (ascan($a1,$n)=-1 and 0=$m) $s=$s+' '+$n endif
next
$arraycomp = split( substr($s,2,len($s)) )
endfunction

_________________________
!

download KiXnet

Top
#73386 - 2003-02-25 03:46 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Even more reliable :



function arraycomp($a1$a2optional $m)
    dim $s
    for each $n in $a2
        if (ascan($a1,$n)>-1 and $m) or (ascan($a1,$n)=-1 and 0=$m$s=$s+'~~~'+$n endif
    next
    $arraycomp = splitsubstr($s,4,len($s)), '~~~' )
endfunction



(Just to avoid splitting elements like " f" )

J.
_________________________



Top
#73387 - 2003-02-25 03:48 PM Re: RE: arraycomp () UDF by Darren
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Updated to Jooel's suggestion, so far...

bye
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#73388 - 2003-02-25 03:49 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
take always the last [Wink]

And don't forget to refresh every 2 minutes here ... LOL [Big Grin]
_________________________



Top
#73389 - 2003-02-25 03:58 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Darren,

this was meant seriously ... just try Lonks latest with :

code:
$arr2 = 1,2,3,4," f",g,a,34,42,23,c,z,o,r

and then try this very line with my latest ...

See ?

(Ok ... one can now cry 'what about elements like '~~~k' [Roll Eyes] [Razz] [Big Grin] )

[ 25. February 2003, 15:59: Message edited by: jpols ]
_________________________



Top
#73390 - 2003-02-25 04:12 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
code:
function arraycomp($1, $2, optional $m)
dim $
for each $n in $2
if (ascan($1,$n)>-1 and $m) or (ascan($1,$n)=-1 and 0=$m) $=$+chr(1)+$n endif
next
$arraycomp=split(substr($,2),chr(1))
endfunction

chr(1) should be more reliable as it's not needed in normal scripting...
_________________________
!

download KiXnet

Top
#73391 - 2003-02-25 04:17 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
not working ... 1 sec.

[ 25. February 2003, 16:18: Message edited by: jpols ]
_________________________



Top
#73392 - 2003-02-25 04:20 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
should copy always the whole udf ... works a treat !

Hey, why did you quit using our baby for posting ?
_________________________



Top
#73393 - 2003-02-25 04:21 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
to be really sad example, another one:
code:
function arraycomp($1, $2, optional $m)
dim $s,$
for each $ in $2
$s=$s+iif((ascan($1,$)>-1 & $m) | (ascan($1,$)=-1 & 0=$m),chr(1)+$,"")
next
$arraycomp=split(substr($s,2),chr(1))
endfunction



[ 25. February 2003, 16:34: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
Page 1 of 3 123>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.086 seconds in which 0.038 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org