Working with data · 17 / 69
Total named stock
YOUR TASK
Make this happen
pairs visits key/value entries in a table, including string keys. Sum values without depending on the iteration order.
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.stock = function(items: { [string]: number }): number
return 0
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("named keys count", function()
local s = subject.load()
t.expect(s.stock({ paper = 12, ink = 3 })):eq(15)
end)
t.it("empty map", function()
local s = subject.load()
t.expect(s.stock({})):eq(0)
end)