Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Make an ASCII table

We're getting markdown tables! I assume this is what they look like:

 data
 data data data
---------------------
 | |
 | |
 | |
 | |

Your task is to make a program or function to generate one of these tables. You'll be given input (string, list of lines, list of characters, etc.) containing data, which looks like this:

datadata
 data
 data data
data data data

The data consists of spaces and non-overlapping datas. The data will not necessarily form neat stacks (it can float in midair). There is guaranteed to be data on the top and bottom lines, as well as some touching the left side. You can choose if the data is right padded with spaces or not.

The table will always be six characters wider than the data, padded three spaces on the left. The table top is directly below the bottom row of data, and is made up of a line of -s.

As for the legs, everyone knows taller tables can support more weight, so they'll need to be one unit tall for every data in the input. They will be made up of |s, one space in from the sides.

This is , so shortest answer in bytes per language wins!

Test cases

Input:

data

Output:

 data
----------
 | |

Input:

data data data
 data data data

Output:

 data data data
 data data data
---------------------
 | |
 | |
 | |
 | |
 | |
 | |

Input:

data
data

Output:

 data
 
 data
----------
 | |
 | |

Answer*

Draft saved
Draft discarded
Cancel
1
  • 1
    \$\begingroup\$ +1. You can save 8 bytes if you have right-padded input and use -F too! Try it online! \$\endgroup\$ Commented Dec 4, 2020 at 13:36

AltStyle によって変換されたページ (->オリジナル) /