Working with data · 14 / 69
Keep positive quantities
YOUR TASK
Make this happen
Build a new array instead of changing the input. table.insert appends one value. Preserve the order of all positive quantities.
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.positive = function(values: { number }): { number }
return values
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("filters zero and negatives", function()
local s = subject.load()
t.expect(s.positive({ 2, 0, -1, 3 })):deep_eq({ 2, 3 })
end)
t.it("empty list", function()
local s = subject.load()
t.expect(#s.positive({})):eq(0)
end)