How to get the bigger string of a table
For example:
Code: Select all
values = {'FirstString', 'SecondString', 'Third String', 'FourString', 'the bigger string of this table'}
Code: Select all
values = {'FirstString', 'SecondString', 'Third String', 'FourString', 'the bigger string of this table'}
Cauan wrote: ↑Tue Sep 05, 2023 5:50 pm Hello!
How to get the bigger string of a table
For example:How to me get the most bigger string of that table with code?Code: Select all
values = {'FirstString', 'SecondString', 'Third String', 'FourString', 'the bigger string of this table'}
Code: Select all
local function getLongestString (list)
local length, longestStr = 0
for i, str in ipairs (list) do
local len = str:length ()
if len > length then
longestStr = str
end
end
return longestStr
end
Code: Select all
--just one modification
function add.getLongestString(list)
local length, longestStr = 0
for i, str in ipairs (list) do
local len = #str
if len > length then
length = len
longestStr = str
end
end
return longestStr
end
Users browsing this forum: slime and 5 guests