1 | get("#515") -- splitLines
|
2 | |
3 | -- each input can be a string or an array of lines |
4 | -- result is as string concatenated with \n |
5 | function mergeTexts(lines1, lines2) |
6 | if type(lines1) == 'string' then lines1 = splitLines(lines1) end |
7 | if type(lines2) == 'string' then lines2 = splitLines(lines2) end |
8 | |
9 | local n = math.max(#lines1, #lines2) |
10 | |
11 | local w = 0 |
12 | for i=1, #lines1 do |
13 | w = math.max(w, #(lines1[i] or '')) |
14 | end |
15 | |
16 | local result = {}
|
17 | for i=1, n do |
18 | local line1 = lines1[i] or "" |
19 | local line2 = lines2[i] or "" |
20 | table.insert(result, line1..string.rep(" ", w-#line1).." | "..line2)
|
21 | end |
22 | return table.concat(result, "\n") |
23 | end |
Began life as a copy of #513
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #517 |
| Snippet name: | mergeTexts (side by side merger, include) |
| Eternal ID of this version: | #517/1 |
| Text MD5: | a8705c22426f8ecc687ade5859d8fb96 |
| Author: | stefan |
| Category: | |
| Type: | Lua code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-03-11 18:56:03 |
| Source code size: | 664 bytes / 23 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 962 / 242 |
| Referenced in: | [show references] |