Last active
August 28, 2018 07:37
-
-
Save lienista/d5b3e8dbf5897e3283ed1aa9721042af to your computer and use it in GitHub Desktop.
Algorithms in Javascript: CTCI 1.3 URLify: Write a function to create an URL by replacing all spaces of an URL string with %20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const createUrl = (s1) => { | |
| let s1Array = s1.split(' '); | |
| let len = s1Array.length - 1; | |
| if(s1Array[len] === '') { | |
| s1Array.pop(); | |
| s1 = s1Array.join(' '); | |
| return createUrl(s1); | |
| } | |
| return s1Array.join('%20'); | |
| } | |
| let u = 'javascript algorithms '; | |
| console.log(createUrl(u)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment