Convert string into an url slug using javascript

Convert string into an url slug using javascript


    //convert string into an url slug using javascript

    function urlSlug(title) {
        return title.toLowerCase().trim().split(/\s+/).join("-");
   }
   // Only change code above this line
   
   console.log(urlSlug("Winter Is Coming")); 
//winter-is-coming
   console.log(urlSlug(" Winter Is  Coming")); 
//winter-is-coming
   console.log(urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone"));
//a-mind-needs-books-like-a-sword-needs-a-whetstone
   console.log(urlSlug("Hold The Door")); 
//hold-the-door