Skip to content
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

Open
jtkaufman737 opened this issue Nov 28, 2018 · 4 comments
Open

1.3 Urlify #4

jtkaufman737 opened this issue Nov 28, 2018 · 4 comments

Comments

@jtkaufman737
Copy link

https://repl.it/@jtkaufman737/LongtermItchySysadmin

@megantaylor
Copy link

megantaylor commented Nov 28, 2018

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()));

@lpatmo
Copy link

lpatmo commented Nov 29, 2018

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 ))

@mcsmithers
Copy link

mcsmithers commented Nov 29, 2018

Christina's Solution

//const textTest = ' Time for a break! ';

function urlifyText() {
  userInput = document.getElementById("userInputBox").value;
  // in case of trailing spaces
  const cleanedUserInput = userInput.trim();
  const urlifiedText = cleanedUserInput.replace(/ /g, '%20');

  // Echo it back
  document.getElementById("urlifiedResultBox").innerHTML = urlifiedText;
}


@rmorabia
Copy link
Owner

rmorabia commented Dec 2, 2018

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants