Turn a Title into a URL Slug

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write slugify(title), which turns a title into the lowercase slug used in a URL. Remove accents, so "é" becomes "e" and "ñ" becomes "n": normalize("NFD") splits an accented letter into the plain letter and a combining mark, and the combining marks are the characters with codes 768 to 879 (hex 300 to 36f); drop those. Remove apostrophes (') entirely, so "What's" becomes "whats". Replace each "&" with the word "and". Then every run of characters other than a to z and 0 to 9 becomes a single hyphen, with no hyphen at the start or end. A title with nothing left gives "". For example, slugify("Crème Brûlée & Tea: What's New?") is "creme-brulee-and-tea-whats-new".

Your code must pass

  • Lowercases and joins words with hyphens
  • Turns runs of other characters into one hyphen
  • Removes accents
  • Drops apostrophes and spells out &
  • Returns an empty string when nothing is left