Skip to content

Instantly share code, notes, and snippets.

@cplpearce
Created August 8, 2020 02:54
Show Gist options
  • Save cplpearce/4589da6f21c46b1e3ae7cfed8de623b2 to your computer and use it in GitHub Desktop.
Save cplpearce/4589da6f21c46b1e3ae7cfed8de623b2 to your computer and use it in GitHub Desktop.
Kata 5 - Percent Encoded String
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