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

Update urlify.js #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions chapter01/1.3 - URLify/urlify.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
var urlify = function(str, length) {
// have a pointer to check from start to end
var strArr = str.split('');
var pointer = 0;
while (pointer < str.length) {
if (strArr[pointer] === ' ') {
// *** needs more work here, a little wierd
// not handling trailing spaces properly
for (var i = str.length - 1; i > pointer + 3; i--) {
strArr[i] = str[i - 2];
}
strArr[pointer] = '%';
strArr[pointer+1] = '2';
strArr[pointer+2] = '0';
console.log(strArr, strArr.length);
}
pointer++;
var strArr = [];
for(var i = 0; i < length; i++) {
strArr[i] = str[i] == ' ' ? '%20' : str[i];
}
// if character is a space, move remainder chars by two
// replace following three chars with '%20'
return strArr.join('');
};

Expand Down