Compare two URLs ignoring trailing slash - Node.js String

Node.js examples for String:URL String

Description

Compare two URLs ignoring trailing slash

Demo Code

function compareURLs(url1, url2) {
  return removeTrailingSlash(url1) == removeTrailingSlash(url2);
}
function removeLeadingSlash(url) {
  return (url[0] == "/") ? url = url.substr(1) : url;
}
function removeTrailingSlash(url) {
  return (url[url.length - 1] == "/") ? url.substr(0, url.length - 1) : url;
}

Related Tutorials