#73374 - 2003-02-24 08:44 PM
RE: arraycomp () UDF by Darren
|
NTDOC
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
|
|
|
|
#73376 - 2003-02-25 01:05 PM
Re: RE: arraycomp () UDF by Darren
|
Jochen
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 )
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, $arr2, 1) $e ? next
get $
;slightly adapted version (not perfect, room for improvement )
function arraycomp($a1, $a2, optional $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
|
|
|
|
#73380 - 2003-02-25 02:47 PM
Re: RE: arraycomp () UDF by Darren
|
Jochen
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, $arr2, 1) $e ? next
get $
;slightly adapted version (not perfect, room for improvement )
function arraycomp($a1, $a2, optional $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]](images/icons/wink.gif) [ 25. February 2003, 15:08: Message edited by: jpols ]
_________________________
|
Top
|
|
|
|
#73384 - 2003-02-25 03:31 PM
Re: RE: arraycomp () UDF by Darren
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
#73388 - 2003-02-25 03:49 PM
Re: RE: arraycomp () UDF by Darren
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
#73389 - 2003-02-25 03:58 PM
Re: RE: arraycomp () UDF by Darren
|
Jochen
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' ) [ 25. February 2003, 15:59: Message edited by: jpols ]
_________________________
|
Top
|
|
|
|
#73393 - 2003-02-25 04:21 PM
Re: RE: arraycomp () UDF by Darren
|
Lonkero
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|