Kata
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example:1
2
3domainName("http://github.com/carbonfive/raygun") == "github"
domainName("http://www.zombie-bites.com") == "zombie-bites"
domainName("https://www.cnet.com") == "cnet"
# My Solutions
1 | function domainName(url){ |
# Others
정규식으로 풀이
1 | function domainName(url){ |
replace() 메소드 사용
1 | function domainName(url){ |
# thoughts
- ‘정규식으로 풀면 되겠구나!’ -> 시간을 재고 푸는중이라 자주 쓰는 방법으로 풀어버렸다.
- 결국 습관적으로 나오는 코드가 본인 실력이겠거니..
- 메소드 반환값이 새로운 것을 반환하는지, 기존 것을 수정하는지 확인하자.