-
Notifications
You must be signed in to change notification settings - Fork 1
/
removeAnchors.js
44 lines (39 loc) · 952 Bytes
/
removeAnchors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
https://dev.to/thepracticaldev/daily-challenge-305-remove-anchors-from-urls-ihp
Complete the function/method so that it returns the url with anything after the anchor (#) removed.
*/
removeUrlAnchor = (str) => str.split('#', 1)[0];
const cases = [
{
label: 'Test 1',
input: removeUrlAnchor('dev.to#about'),
shouldBe: 'dev.to'
},
{
label: 'Test 2',
input: removeUrlAnchor('www.telegraph.co.uk/branding'),
shouldBe: 'www.telegraph.co.uk/branding'
},
{
label: 'Test 3',
input: removeUrlAnchor('www.twitter.com?page=1'),
shouldBe: 'www.twitter.com?page=1'
},
{
label: 'Test 4',
input: removeUrlAnchor('www.twitter.com#about'),
shouldBe: 'www.twitter.com'
}
]
cases.map((test) =>
console.log(
(test.input === test.shouldBe ? '✅' : '❗') +
' ' +
test.label +
' => ' +
'Should be: ' +
test.shouldBe +
' received: ' +
test.input
)
)