Render Sidebar Labels as HTML
Problem statement
For this exercise, render the supplied ordered text labels as one sidebar HTML string.
- Begin with exactly
<aside><ul>. - For every label in input order, append
<li>, the escaped label, and</li>. - End with exactly
</ul></aside>.
Inside each label, replace & with &, < with <, and > with >. Copy every other character unchanged, including quotes and spaces. Interpret the input as literal text, so entity-looking strings are escaped too.
- Preserve item order, duplicate labels and empty labels.
- An empty input list produces only the outer wrapper.
- Add no extra whitespace, attributes, links, styling or routing behavior.
The source did not supply original markup, item data or a repository. This callable renderer is the explicit practice representation of the reported sidebar-rendering task.
Function
renderSidebar(labels: String[]) → StringExamples
Example 1
labels = ["One","Two"]return = "<aside><ul><li>One</li><li>Two</li></ul></aside>"Each label becomes one list item in the same order.
Example 2
labels = ["A&B","<tag>"]return = "<aside><ul><li>A&B</li><li><tag></li></ul></aside>"Ampersands and angle brackets in labels become text-node entities; only the fixed wrapper creates markup.
Constraints
0 <= labels.length <= 1000.- Every label contains only printable ASCII characters with codes from
32through126; empty labels are allowed. - The sum of all label lengths is at most
1000.