Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created October 7, 2022 18:59
Show Gist options
  • Save IrhaAli/c185a9f190aee5d887748450bb1ea02a to your computer and use it in GitHub Desktop.
Save IrhaAli/c185a9f190aee5d887748450bb1ea02a to your computer and use it in GitHub Desktop.
Adds %20 to empty parts of the string
const urlEncode = function(text) {
//removes the outer empty spaces
let newText = text.trim().split('');
let textSize = text.length;
//check through the rest of the string
for (i = 0; i < textSize; i++){
if (newText[i] === ' '){
newText[i] = '%20';
}
}
return newText.join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment