question 57 Strings & Text · medium
A web address for a product
Runtime Market builds each product page's web address from the product's name, as a *slug* such as deluxe-pillow-blue-2-pack. Lower-case the name. Keep the letters a–z and the digits 0–9. Turn each space or dash into a single -, but never put two - in a row and never start the slug with one. Drop every other character, then remove a - left at the end.
Input
name, a product nameKeep
a–z and 0–9 after lower-casingSeparatorsa space or
- becomes -, unless the slug is still empty or already ends with -Printsthe slug, with no
- at either endExamples
"Deluxe Pillow (Blue) 2-Pack" → deluxe-pillow-blue-2-pack; " Mini Knife Set " → mini-knife-setExpected output1 line
- 1deluxe-pillow-blue-2-pack