Re: find_all() And More
- Posted by mattlewis (admin) Sep 29, 2010
- 1088 views
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