Skip to content

Commit b533d9f

Browse files
committed
Update 1.3 with Regex solution
1 parent f533992 commit b533d9f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Write a method to replace all spaces within a string with '%20'
22

3-
const URLify = (string) => string.split(' ').join('%20');
3+
const encodeSpaces = (string) => string.replace(/ /g, '%20');
44

55
// Tests:
6-
console.log(URLify('Hello World') === 'Hello%20World');
7-
console.log(URLify('') === '');
8-
console.log(URLify('This is an example') === 'This%20is%20an%20example');
6+
console.log(encodeSpaces('Hello World') === 'Hello%20World');
7+
console.log(encodeSpaces('') === '');
8+
console.log(encodeSpaces('This is an example') === 'This%20is%20an%20example');

0 commit comments

Comments
 (0)