Re: Fastest Way to...
- Posted by Derek Parnell <ddparnell at bigpond.com> Oct 28, 2003
- 388 views
----- Original Message ----- From: "C. K. Lester" <euphoric at cklester.com> To: <EUforum at topica.com> Subject: Fastest Way to... > > > I've got a 3-element sequence... > > { 3, -1, 0 } > > and need to turn it into this > > { 1, -1, 0 } > > That is, any positive values ( > 0 ) should be turned to one. > > What's the fastest way to do this? Right now I'm using > > if pos[1] > 0 then > pos[1] = 1 > end if > if pos[2] > 0 then > pos[2] = 1 > end if > if pos[3] > 0 then > pos[3] = 1 > end if > > I have a feeling this is fastest. Will it be as fast if put in a loop > for arbitrary length? > Maybe this... pos = pos * (pos <= 0) + (pos > 0) -- Derek