How to resolve the algorithm Comma quibbling step by step in the Lua programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Comma quibbling step by step in the Lua programming language
Table of Contents
Problem Statement
Comma quibbling is a task originally set by Eric Lippert in his blog.
Write a function to generate a string output which is the concatenation of input words from a list/sequence where:
Test your function with the following series of inputs showing your output here on this page:
Note: Assume words are non-empty strings of uppercase characters for this task.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Comma quibbling step by step in the Lua programming language
Source code in the lua programming language
function quibble (strTab)
local outString, join = "{"
for strNum = 1, #strTab do
if strNum == #strTab then
join = ""
elseif strNum == #strTab - 1 then
join = " and "
else
join = ", "
end
outString = outString .. strTab[strNum] .. join
end
return outString .. '}'
end
local testCases = {
{},
{"ABC"},
{"ABC", "DEF"},
{"ABC", "DEF", "G", "H"}
}
for _, input in pairs(testCases) do print(quibble(input)) end
You may also check:How to resolve the algorithm Haversine formula step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Last Friday of each month step by step in the Clojure programming language
You may also check:How to resolve the algorithm Largest int from concatenated ints step by step in the AWK programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Cowgol programming language
You may also check:How to resolve the algorithm SQL-based authentication step by step in the Perl programming language