-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathurlify.js
More file actions
15 lines (13 loc) · 546 Bytes
/
Copy pathurlify.js
File metadata and controls
15 lines (13 loc) · 546 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// URLify: Write a method to replace all spaces in a string with
// '%20: You may assume that the string has sufficient space at the
// end to hold the additional characters, and that you are given the
// "true" length of the string. (Note: If implementing in Java,
// please use a character array so that you can perform this operation
// in place.)
function urlify(input) {
const formattedUrl = input.trim().replace(/ /g, "%20");
console.log(formattedUrl);
return formattedUrl;
}
urlify("he llo ");
urlify("Mr John Smith ");