OverHash / Roblox-TS-Libraries

Libraries I have created for Roblox-TS and npm
12 stars 15 forks source link

tableutil.Shuffle has the wrong return type #14

Closed Jxl-s closed 3 years ago

Jxl-s commented 3 years ago

it seems like tableutil.Shuffle doesn't return anything, but mutates the original array

local function Shuffle(tbl)
    assert(type(tbl) == "table", "First argument must be a table")
    local rng = Random.new()
    for i = #tbl, 2, -1 do
        local j = rng:NextInteger(1, i)
        tbl[i], tbl[j] = tbl[j], tbl[i]
    end
end
OverHash commented 3 years ago

Thanks for alerting me about this issue via this PR! This module is meant to be immutable data changes, so whilst fixing the types does make it more type-accurate, it does not solve the root problem (it should return a new table)

Sleitnick recently made a big change to the original tableutil module making it completely immutable, so I'll probably end up checking all the types sometime tomorrow when I update the module to that commit.

Thanks for alerting this to my attention though!