#How to Extract Duplicates from a table/string
146 messages · Page 1 of 1 (latest)
local t = {1, 1, 4, 9, 12, 8, 6, 9, 9}
for _, number in t do
local duplicates = {}
for __, duplicate in t do
if duplicate == number then
table.insert(duplicates, duplicate)
end
end
end
@unique solar
then concat
this just adds them up, so it doesn't work
oh sorry, it doesn't add them up but it actually gives this error got something mixed up my bad:
ye
I have another thing that works, so it's aight if you don't know
until you figure something out I will return it to how it was
no the duplicates would be shortened to just 1,9
alr
but that works too I could just tweak it
local t = "1, 1, 4, 9, 12, 8, 6, 9, 9"
local characters = string.split(t, ",")
local duplicateString = ""
for _, v in characters do
v = tonumber(v)
local found = 0
for _, dupe in characters do
if tonumber(dupe) == v then
found += 1
end
end
if found >= 2 and not string.match(duplicateString, v) then
duplicateString = duplicateString..v..","
end
end
print(duplicateString)
here
lmk
if it woroks
still don't work anyway
Intersects.MouseButton1Click:Connect(function()
local SetBox1 = CalculatorGui.Frame.Sets:WaitForChild("1")
local SetBox2 = CalculatorGui.Frame.Sets:WaitForChild("2")
local SetBox3 = CalculatorGui.Frame.Sets:WaitForChild("3")
if one.BackgroundColor3 == Color3.new(1,0,0) and two.BackgroundColor3 == Color3.new(1,0,0)
and three.BackgroundColor3 == Color3.new(1,0,0) then
local FullSet1to2to3 = string.sub(SetBox1.Text, 1, -2)..","..string.sub(SetBox2.Text, 2, -2)..","..string.sub(SetBox3.Text, 2, -1)
local Characters = {}
local myString = FullSet1to2to3
local characters = string.split(FullSet1to2to3, ",")
local duplicateString = ""
for _, v in characters do
v = tonumber(v)
local found = 0
for _, dupe in characters do
if tonumber(dupe) == v then
found += 1
end
end
if found >= 2 and not string.match(duplicateString, v) then
duplicateString = duplicateString..v..","
end
end
if duplicateString ~= "" then
Output.Text = "Output:\n ".."{"..duplicateString.."}"
end
end
end)```
it doesn't execute due to this error:
Players.combinationto.PlayerScripts.LocalScript:508: invalid argument #2 to 'match' (string expected, got nil)
so you gotta fix it first
I could print somewhere else actually hold on
oh now that I did that,
FullSet1to2to3 when printed outputs: {1,2,3,4,1,3}
local FullSet1to2to3 = string.sub(SetBox1.Text, 1, -2)..","..string.sub(SetBox2.Text, 2, -2)..","..string.sub(SetBox3.Text, 2, -1)
print(FullSet1to2to3)
local Characters = {}
local myString = FullSet1to2to3
local characters = string.split(FullSet1to2to3, ",")
local duplicateString = ""
for _, v in characters do
v = tonumber(v)
local found = 0
for _, dupe in characters do
if tonumber(dupe) == v then
found += 1
end
end
if found >= 2 and not string.match(duplicateString, v) then
duplicateString = duplicateString..v..","
end
end
if duplicateString ~= "" then
Output.Text = "Output:\n ".."{"..duplicateString.."}"
end
end
end)
end
end)```
if you don't know it's fine, as I've said I already have another working method
well you got the script lol
Players.combinationto.PlayerScripts.LocalScript:491: attempt to iterate over a string value
errorline:
for _, v in FullSet1to2to3 do
local FullSet1to2to3 = string.sub(SetBox1.Text, 1, -2)..","..string.sub(SetBox2.Text, 2, -2)..","..string.sub(SetBox3.Text, 2, -1)
print(FullSet1to2to3)
local Characters = {}
local myString = FullSet1to2to3
local characters = string.split(FullSet1to2to3, ",")
local duplicateString = ""
for _, v in FullSet1to2to3 do
v = tonumber(v)
local found = 0
for _, dupe in characters do
if tonumber(dupe) == v then
found += 1
end
end
if found >= 2 and not string.match(duplicateString, v) then
duplicateString = duplicateString..v..","
end
end
if duplicateString ~= "" then
Output.Text = "Output:\n ".."{"..duplicateString.."}"
end
end
end)```
oh wait
wtf
im confused
how is ur textbox
supposed to look like
when u type in something
why are u doing subbing
because it's two textboxes that look like this:
{1,2,3,4} - {2,3,4}
therefore the string.sub("string", 1, -2) and string.sub("string",2,-1)
to handle the curly brackets yk
did it print whats FullSet1to2to3
yes I already told you
right here
why does it still have curly brackets
the string.sub() leaves certain brackets per string so it can result in a string that has {}
cant u have
TextLabal TextBox TextLabel
and the textlabel
has text
of curly bracket?
yeah
yours or mine
local FullSet1to2to3 = "{1, 1, 1, 8, 10, 88, 40}"
--local FullSet1to2to3 = string.sub(SetBox1.Text, 1, -2)..","..string.sub(SetBox2.Text, 2, -2)..","..string.sub(SetBox3.Text, 2, -1)
print(FullSet1to2to3)
local Characters = {}
local myString = FullSet1to2to3
local characters = string.split(FullSet1to2to3, ",")
local duplicateString = ""
for _, v in characters do
v = tonumber(v)
local found = 0
for _, dupe in characters do
if tonumber(dupe) == v then
found += 1
end
end
if found >= 2 and not string.match(duplicateString, v) then
duplicateString = duplicateString..v..","
end
end
if duplicateString ~= "" then
Output.Text = "Output:\n ".."{"..duplicateString.."}"
end
end
end)
try this
you should get
why did you comment the current one
to see if it works
with custom
cuz its not supposed to be nil
if it prints its a string
bro omg the damn problem is infront of your fucking eyes.
the error message says it loud and clear but you can't listen for shit
Fullset1to2to3 works perfectly fine it's something with it, it's your logic
THATS CUZ V IS NIL
** You are now Level 11! **
MEANING CHARACTERS
IS ALSO nil
NOT A TABLE
YOU FUCKING IDIOT
DONT EVEN TRY TO SAY SHIT
nah pretty sure Fullset is a real string
mf I said I got a working method
you want proof?
cuz I am tired of your dumbass
thought you could provide me with an actually better method
I thought wrong
I will send proof
learn basic brain usage
lua compiler is different than studio
its different in things that studio has
but compiling is same
u fucking idiot
also
print ur characters table
local function extractDuplicates(str)
local seen = {}
local duplicates = {}
for i = 1, #str do
local char = str:sub(i, i)
if char ~= "{" and char ~= "}" and char ~= "," then
if seen[char] then
duplicates[char] = true
else
seen[char] = true
end
end
end
return duplicates
end
local duplicates = extractDuplicates(myString)
local duplicateString = ""
for char, _ in pairs(duplicates) do
duplicateString = duplicateString..","..char
if duplicateString:sub(1,1) == "," then
duplicateString = ""..duplicateString:sub(2,-1)
end
end
if duplicateString ~= "" then
Output.Text = "Output:\n ".."{"..duplicateString.."}"
end
end
end)```
now you can shut the fuck up
dumb shit
tired of you know it all wannabes
ofc comments about other random shit, because he knows he's full of shit
shinyspatula has been warned. || asking for help in #1020374354867007528 and then being toxic to those who try to help u 💀