← Lua Academy

Working with data · 20 / 69

Normalise a code

YOUR TASK

Make this happen

3 steps
  1. Normalisation reduces accidental differences in input. Convert an ASCII product code to uppercase using the string library.

  2. Read the cases in lesson.test.lua, then choose Check solution to see what needs to change.

  3. Update subject.lua until every test passes. Keep the supplied tests unchanged.

Read the starter and tests

subject.lua

exports.normalise = function(code: string): string
  return code
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")

t.it("mixed case", function()
  local s = subject.load()
  t.expect(s.normalise("Ab-12")):eq("AB-12")
end)

t.it("already uppercase", function()
  local s = subject.load()
  t.expect(s.normalise("AB")):eq("AB")
end)