lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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