-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.3 Urlify #4
Comments
https://repl.it/@megantaylor/URLify //use .map()
function URLifyMap(str) {
let urlified = [...str.trim()].map(char => {
if(char === " ") {
return "%20";
} else {
return char;
}
});
return urlified.join("");
}
//use .split()
function URLifySplit(str) {
return str.trim().split(' ').join('%20');
}
//encodeURI
const url = "Mr John Smith ";
encodeURI(url);
console.log(encodeURI(url.trim())); |
https://repl.it/@lpatmo/TurboKnowingDictionary-1 /*Write a method to replace all spaces in a string with '%20'. You may assume that the string
has sufficient space at the end to hold the additional characters, and that you are given the "true"
length of the string. (Note: If implementing in Java, please use a character array so that you can
perform this operation in place.)*/
// Input: "Mr John Smith ", 13
// Output: "Mr%20John%20Smith"
function replaceWithPercent20(str, limit) {
//Create new emptry str
//Loop through old string
//If char is space, then add %20 to Input
//Otherwise, add that char to the new string
let newStr = '';
for (let i = 0; i < limit; i++) {
if (str[i] === ' ') {
newStr += '%20';
} else {
newStr += str[i];
}
}
return newStr;
}
console.log(replaceWithPercent20("Mr John Smith ", 13 )) |
|
https://repl.it/@rmorabia/MidnightblueBlackAngles const url = (str) => {
const string = str.replace(/\s+/g,' ').trim().split('')
for (let i = 0; i < string.length; i++) {
if (string[i] === ' ') {
string.splice(i, 1, '%20')
}
}
return string.toString().replace(/,/gi, '')
}
console.log(url('cO o l ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://repl.it/@jtkaufman737/LongtermItchySysadmin
The text was updated successfully, but these errors were encountered: