Re: find_all() And More

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...
a = { 0, 1, 2, 3, 0 } 
find_all( 0, a ) -- is { 1, 5 } 

Is there a lib function that will let me do a find for "anything but 0" such that it returns { 2, 3, 4 }?

I guess I could do:

a = { 0, 1, 2, 3, 0 } 
b = a = 0 
find_all( 0, b ) -- is now { 2, 3, 4 } 

I just want what's fastest. :)

I'd try something like this:

constant a = { 0, 1, 2, 3, 0 }  
 
function find_all_but( object needle, sequence haystack ) 
	integer ix = 1 
	integer jx 
	sequence found = {} 
	while jx with entry do 
		for i = ix to jx - 1 do 
			found &= i 
		end for 
		ix = jx + 1 
	entry 
		jx = find( needle, haystack, ix ) 
	end while 
	return found 
end function 
 
? find_all_but( 0, a ) 

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu