Anonymous

Module:Shared: Difference between revisions

From Melvor Idle
Implement joinList()
(numStrWithSign: Shared -> p)
(Implement joinList())
Line 365: Line 365:
   else
   else
     return p.formatnum(number)
     return p.formatnum(number)
  end
end
-- Takes a table input with elements of type string, returning a string formed from
-- each element separated by the specified delimiter. Optionally uses a different delimiter
-- for the last two elements
function p.joinList(list, sep, lastSep)
  if lastSep ~= nil and #list > 1 then
    return string.sub(table.concat(list, sep), 1, -(1 + string.len(sep) + string.len(list[#list]))) .. lastSep .. list[#list]
  else
    return table.concat(list, sep)
   end
   end
end
end


return p
return p