testtable1 = {1,1,1,1,2,2,2,2,3,3,3,3,5,5,5}
I want to create another table who one element of each in testtable1 --->
testtable2 = {1,2,3,5}
I think there is a kind of table.something? Like table.sort?
Ty for helping
function unique(t) 	local r = {} 	local i = {} 	for k,v in pairs(t) do 		if not i[v] then 			r[#r+1] = v 			i[v] = 1 		end 	end 	return r end a = unique({1,4,5,2,2,3,4}) for k,v in pairs(a) do print(v) end
table.remove()many times.
table.remove( testtable1, math.random(1, #testtable1) )
math.random()picks randomly a value from the table and then it gets removed.
function randomt(table, number) 	local t = {} 	for k, v in pairs(table) do 		if v == number then 			table.insert(t, k) 		end 	end 	if #t > 0 then 		table.remove(table, math.random(#t)) 	end end
function differents(table) 	local d = 0 	local c 	for k, v in pairs(table) do 		if not c or c ~= v then 			d = d + 1 			c = v 		end 	end 	return d end function tableif(t,s) 	for k, v in pairs(t) do 		if v == s then 			return true 		end 	end 	return false end function tablesort(table) 	local t = {} 	local c = false 	for i = 1, differents(table) do 		for k, v in pairs(table) do 			if not c and not tableif(t,v) then 				c = v 			end 			if v == c then 				table.insert(t,v) 			end 		end 		c = false 	end 	return t end
differentstells me how many different things in table.
tableiftells me if selected number is in table. And finally,
tablesortis what you are looking for.
tablesort(TestTable)
function tablesort(table) local t = {} local c = false for i = 1, differents(table) do for k, v in pairs(table) do if not c and not tableif(t,v) then c = v end if v == c then ---->table.insert(t,v)<----- end end c = false end return t end
function tablesort(tables) local t = {} local c = false for i = 1, differents(tables) do for k, v in pairs(tables) do if not c and not tableif(t,v) then c = v end if v == c then table.insert(t,v) end end c = false end return t end
function differents(table) local d = 0 local c for k, v in pairs(table) do if not c or c ~= v then d = d + 1 c = v end end return d end function tableif(t,s) for k, v in pairs(t) do if v == s then return true end end return false end function tablesort(tables) local t = {} local c = false for i = 1, differents(tables) do for k, v in pairs(tables) do if not c and not tableif(t,v) then c = v end if v == c then table.insert(t,v) end end c = false end return t end function unique(t) local r = {} local i = {} for k,v in pairs(t) do if not i[v] then r[#r+1] = v i[v] = 1 end end return r end
TestTable = {3,4,3,6,2,1,6,4,2,6,6,1,3,6} print(table.concat(TestTable, ", ")) function greetSort(tbl) 	-- the smaller the value - the closer to the beginning of the sorted table a value must be 	-- small values = first 	-- large values = last 	local nextValAt = {} 	local itemsMoved, steps = 0, 0 	for i = 1, #tbl do 		steps = steps + 1 		local item = tbl[i] 		if not nextValAt[item] then 			nextValAt[item] = i+1 			--print("i=".. i, "New unknown value: ".. item, "New Rank: ".. i+1) 			 		-- don't try to replace the currently existing same item 		-- e.g: 5,5 - don't start the copying process of the latter 5 		elseif item == tbl[nextValAt[item]] then 			nextValAt[item] = nextValAt[item] + 1 			--print("Item ".. item .." is in the correct pos. Increasing value of ".. item .." by 1 -> ".. nextValAt[item]) 		else 			--print("i=".. i, " known value: ".. item, "Inserting as #".. nextValAt[item], "Between ".. (tbl[nextValAt[item]-1] or "@") .." and ".. (tbl[nextValAt[item]] or "@")) 			table.insert(tbl, nextValAt[item], item) 			itemsMoved = itemsMoved + 1 			 			repeat 				nextValAt[item] = nextValAt[item] + 1 				--print("Increasing value of ".. item .." by 1 -> ".. nextValAt[item]) 				if nextValAt[item] > i then break end 				item = tbl[nextValAt[item]] 				steps = steps + 1 			until item == nil 			table.remove(tbl, i+1) 			 		end 	end 	print("steps: ".. steps, "itemsMoved: ".. itemsMoved) end greetSort(TestTable) print(table.concat(TestTable, ", "))