--!native --!optimize 2 -- Compiled with roblox-ts v3.0.0 local TS = _G[script] local SubString = TS.import(script, script.Parent.Parent, "Utils", "SubString") local mapping = { B = "1", F = "1", P = "1", V = "1", C = "2", G = "2", J = "2", K = "2", Q = "2", S = "2", X = "2", Z = "2", D = "3", T = "3", L = "4", M = "5", N = "5", R = "6", } local vovels = string.split("AEIOUHWY", "") local padding = "0000" local function SoundexTransform(input) if #input == 0 then return padding end local s = string.split(string.upper(input), "") local firstChar = s[1] local soundexCode = { firstChar } local previousCode = "" -- Process remaining characters (skip vowels/h/w/y) for i = 1, #s - 1 do local char = s[i + 1] if table.find(vovels, char) ~= nil then continue end local _condition = mapping[char] if _condition == nil then _condition = "" end local code = _condition local _condition_1 = code if _condition_1 ~= "" and _condition_1 then _condition_1 = code ~= previousCode end if _condition_1 ~= "" and _condition_1 then table.insert(soundexCode, code) previousCode = code end end -- Build final code: first letter + 3 digits, padded/truncated local code = SubString(`{table.concat(soundexCode, "")}{padding}`, 0, 4) return code end return { SoundexTransform = SoundexTransform, }