One regex bug in this formatter.
function slugify(title) {
return title.trim().toLowerCase().replace('/\s+/g', '-');
}
console.log(slugify('Hello World Again'));
Reply with what is broken and how you would fix it.
One regex bug in this formatter.
function slugify(title) {
return title.trim().toLowerCase().replace('/\s+/g', '-');
}
console.log(slugify('Hello World Again'));
Reply with what is broken and how you would fix it.
Your regex is a string literal, not a RegExp, so . replace() is looking for the exact characters "/\s+/g" instead of matching whitespace. Fix it by using a real regex (no quotes): title. trim(). toLowerCase(). replace(/\s+/g, '-').
:: Copyright KIRUPA 2024 //--