Remove anchor from URL

Lee·2022년 9월 3일

Algorithm

목록 보기
88/92
post-thumbnail

❓ Remove anchor from URL

Q. Complete the function/method so that it returns the url with anything after the anchor (#) removed.

Examples
"www.codewars.com#about" --> "www.codewars.com"
"www.codewars.com?page=1" -->"www.codewars.com?page=1"

✔ Solution

//#my solution
function removeUrlAnchor(url){
  return url.split('#')[0];
}

//#other solution
const removeUrlAnchor = url => url.replace(/#.+$/,'');
profile
Lee

0개의 댓글