Practical scripting · 66 / 69
Keep unique identifiers
YOUR TASK
Make this happen
Use a set-like map to remember identifiers already seen. Return each identifier once, preserving the order of its first appearance.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
exports.unique = function(values: { string }): { string }
return values
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("keeps first occurrence", function()
local s = subject.load()
t.expect(s.unique({ "b", "a", "b", "c", "a" })):deep_eq({ "b", "a", "c" })
end)
t.it("empty input", function()
local s = subject.load()
t.expect(#s.unique({})):eq(0)
end)