Provide an overview of:
- What does the code do and what are you not satisfied with?
The function below basically takes a table of strings and converts them into string .. X
if there are duplicates of string
found in the table. Here’s an example:
Calling the function:
local nameSet = {"Zombie", "Zombie", "Fast Zombie"}
local newNameSet = ABCTargets(nameSet)
print(newNameSet)
Expected to print:
{"Zombie A", "Zombie B", "Fast Zombie"}
(It doesn’t count stand-alone strings and only accounts for duplicates.)
Problem:
I feel like this takes too long for the client to execute and it will drag down the feel of swiftness in the UI
- What potential improvements have you considered?
Make the server run it but that only seems to make it slower since I have to fire a remote function and stuff like that
- How (specifically) do you want to improve the code?
I would like it to
A: Be neater
B: Be faster, if possible
Without further ado, here ya go:
function ABCTargets(dataSet)
--if runService:IsServer() then
if dataSet then
local contenderSet = {}
local editiedNames = {}
local alphabet = {"A", "B", "C", "D", "E", "F", "G", "H"}
for _, contender in dataSet do -- Raw Data -> Names
table.insert(contenderSet, {contender["Name"], contender["ContenderIndex"], contender["Type"]})
end
for _, contender in contenderSet do -- Names -> Table segregation
if editiedNames[contender[1]] then -- Name check
table.insert(editiedNames[contender[1]], contender)
else
editiedNames[contender[1]] = {contender}
end
end
table.clear(contenderSet)
for _, contender in editiedNames do -- Table segregation -> Name giving
if table.maxn(contender) > 1 then
for alphabetIndex, newContender in contender do
table.insert(contenderSet, {newContender[1] .. " " .. alphabet[alphabetIndex] or "Error", newContender[2], newContender[3]})
end
else
for _, newContender in contender do
table.insert(contenderSet, newContender)
end
end
end
return contenderSet
end
--[[elseif runService:IsClient() then
local reqFunc = repStorage.RemoteFunctions.DoABCTargets
local returnedData = reqFunc:InvokeServer(dataSet)
return returnedData
end]]
end