lua-users home
lua-l archive

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


On 23/07/18 15:07, Scott Morgan wrote:
> How about:
> 
> function concat(list, sep, i, j)
>   i = i or 1
>   j = j or #list
> 
>   local tmp = {}
>   for i=1,#list do
>     tmp[i] = tostring(list[i])
>   end
>   return table.concat(tmp, sep, i, j)
> end
> 
> Which would just be O(n)?
> 
> Might be able to improve with table.pack/unpack, maybe.

And I notice the mistake in the loop, doh!

Should be `for k=i,j do` etc. etc.

Scott