Skip to content

Instantly share code, notes, and snippets.

@ChrisVilches
Last active October 7, 2021 16:32
Show Gist options
  • Save ChrisVilches/cced83ae2ac31be5d095debd3ce88e1b to your computer and use it in GitHub Desktop.
Save ChrisVilches/cced83ae2ac31be5d095debd3ce88e1b to your computer and use it in GitHub Desktop.
// normalizeTitle :: String -> String
const normalizeTitle = rawTitle => {
const parts = rawTitle.split(" - ");
const right = parts[1].toLowerCase().replace(/\s/g, "_").replace(/[^a-z_0-9]+/g, "");
return `${parts[0]}-${right}`;
}
const rawTitle = document.getElementById("problem-name").innerHTML;
normalizeTitle(rawTitle);
// Example
// input: EASYPROB - A Very Easy Problem!
// output: EASYPROB-a_very_easy_problem
// Useful for getting a name that can be used in a code file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment