Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.0 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69162d64f96574d9bb629f00 Challenge 115: Markdown Ordered List Item Converter 28 challenge-115

--description--

Given a string representing an ordered list item in Markdown, return the equivalent HTML string.

A valid ordered list item in Markdown must:

  • Start with zero or more spaces, followed by
  • A number (1 or greater) and a period (.), followed by
  • At least one space, and then
  • The list item text.

If the string doesn't have the exact format above, return "Invalid format". Otherwise, wrap the list item text in li tags and return the string.

For example, given "1. My item", return "<li>My item</li>".

Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.

--hints--

convertListItem("1. My item") should return "<li>My item</li>".

assert.equal(convertListItem("1. My item"), "<li>My item</li>");

convertListItem(" 1. Another item") should return "<li>Another item</li>".

assert.equal(convertListItem(" 1.  Another item"), "<li>Another item</li>");

convertListItem("1 . invalid item") should return "Invalid format".

assert.equal(convertListItem("1 . invalid item"), "Invalid format");

convertListItem("2. list item text") should return "<li>list item text</li>".

assert.equal(convertListItem("2. list item text"), "<li>list item text</li>");

convertListItem(". invalid again") should return "Invalid format".

assert.equal(convertListItem(". invalid again"), "Invalid format");

convertListItem("A. last invalid") should return "Invalid format".

assert.equal(convertListItem("A. last invalid"), "Invalid format");

--seed--

--seed-contents--

function convertListItem(markdown) {

  return markdown;
}

--solutions--

function convertListItem(markdown) {
  const match = markdown.match(/^\s*(\d+)\.\s+(.+)$/);
  if (!match) return "Invalid format";

  const text = match[2];
  return `<li>${text}</li>`;
}