Working with data · 15 / 69
Transform every entry
YOUR TASK
Make this happen
A transformation produces one output for every input. Convert centimetres to millimetres while preserving array order and leaving the input untouched.
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.millimetres = function(values: { number }): { number }
return values
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("converts all values", function()
local s = subject.load()
t.expect(s.millimetres({ 2, 3.5 })):deep_eq({ 20, 35 })
end)
t.it("does not mutate input", function()
local s = subject.load()
local input = { 2 }
s.millimetres(input)
t.expect(input[1]):eq(2)
end)