Created
December 13, 2018 19:10
-
-
Save kevinahn7/3fa8eed7f0db0d7d91d86a1307fe2d06 to your computer and use it in GitHub Desktop.
Question from CtCI
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
let test = "Mr John Smith "; | |
function urlify(string) { | |
let stringArray = string.split(" "); | |
let filteredArray = stringArray.filter(x => x != "") | |
let newFilteredArray = filteredArray.join(" ").split("") | |
for (let x = 0; x < newFilteredArray.length; x++) { | |
if (newFilteredArray[x] === " ") { | |
newFilteredArray[x] = "%20" | |
} | |
} | |
return newFilteredArray.join("") | |
} | |
console.log(urlify(test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment