[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: filter an array in place
- From: Romulo <romuloab@...>
- Date: Fri, 14 Jan 2011 11:55:23 -0200
On Fri, Jan 14, 2011 at 02:30, Drake Wilson <drake@begriffli.ch> wrote:
> Quoth Emmanuel Oga <emmanueloga@gmail.com>, on 2011-01-14 01:12:40 -0300:
>> Is there any other more elegant way?
>
> There's not much that's "elegant" in the sense of "easy using the Lua
> table library" or such, that I can see. If I were coding it all the
> way down, I'd do something like this:
> [snip]
I've submitted a variant of your code to LuaSnippets[1]. My function
removes a element according to the predicated, instead of keeping it.
The function is optimized to avoid unnecessary table assignments by
finding contiguous slots "marked" as to-be-kept.
--rb
[1] http://snippets.luacode.org/snippets/Filter_a_table_in-place_2_120