lua-users home
lua-l archive

Re: Why is nil not a valid table key?

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


On Nov 26, 2005, at 10:10, Philippe Lhoste wrote:
My solution (I didn't looked at your before doing it, to avoid to be spoiled...):
Another one, just for the fun of it :))
function valuesIndices( someValues )
 local someIndices = LUList()
 for _, aValue in someValues:iterator() do
 someIndices:add( someValues:indexOf( aValue ) )
 end
 return someIndices
end
print( valuesIndices( LUList( { 0, 1, 4, 2, 4, 1, 0, 2 } ) ) )
> { 1, 2, 3, 4, 3, 2, 1, 4 }
print( valuesIndices( LUList( { "a", "b", "e", "c", "e", "b", "a", "c" } ) ) )
> { 1, 2, 3, 4, 3, 2, 1, 4 }
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/

AltStyle によって変換されたページ (->オリジナル) /