Created
August 8, 2020 02:54
-
-
Save cplpearce/4589da6f21c46b1e3ae7cfed8de623b2 to your computer and use it in GitHub Desktop.
Kata 5 - Percent Encoded String
This file contains 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 urlEncode = function(text) { | |
let newURL = ""; | |
for (let c = 0; c < text.length; c++) { | |
text[c] === " " ? (c === 0 || c === text.length - 1) ? null : newURL += "%20" : newURL += text[c] | |
} | |
return newURL; | |
}; | |
console.log(urlEncode("Lighthouse Labs")); | |
console.log(urlEncode(" Lighthouse Labs ")); | |
console.log(urlEncode(" this is a test how is it going?")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment