[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: filter an array in place
- From: Eduardo Ochs <eduardoochs@...>
- Date: Fri, 14 Jan 2011 22:00:30 -0200
On Fri, Jan 14, 2011 at 2:45 PM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Fri, Jan 14, 2011 at 6:33 PM, Romulo <romuloab@gmail.com> wrote:
>> On Fri, Jan 14, 2011 at 13:06, Drake Wilson <drake@begriffli.ch> wrote:
>>> I don't have a version at LuaSnippets. I posted a function to the
>>> list. If someone reposted it at LuaSnippets, that's news to me.
>>
>> Sorry. I didn't know that.
>
> I think I was a little too eager to contribute Drake's code as a
> snippet, especially since I neglected to actually log in and leave a
> proper audit trail ;)
>
> So, I'm also sorry that this caused confusion.
>
> steve d.
filterinplace = function (cond, T)
local oldsize, newsize = #T, 0
for i=1,oldsize do
if cond(T[i]) then
newsize = newsize + 1
T[newsize] = T[i]
-- ^ or: if newsize ~= i then T[newsize] = T[i] end
end
end
for i=newsize+1,oldsize do
T[i] = nil
end
return T
end