Working with data · 13 / 69
Start at one
YOUR TASK
Make this happen
The first element of a Lua array is at index 1. This exercise uses a guaranteed nonempty array; later lessons handle missing elements with optional types.
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.first = function(values: { string }): string
return values[2]
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("first entry", function()
local s = subject.load()
t.expect(s.first({ "alpha", "beta" })):eq("alpha")
end)