-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from dawsonbotsford/master
Removed node_modules and completed 1_2 and 1_3
- Loading branch information
Showing
270 changed files
with
94 additions
and
71,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = Strings_1_2 = (function() { | ||
return { | ||
|
||
// NOT inline solution (left here to learn from) | ||
// reverseString: function(str) { | ||
// if (str.length === 0) { | ||
// return ''; | ||
// } | ||
// return str[str.length - 1] + arguments.callee(str.substr(0, str.length - 1)); | ||
// } | ||
// | ||
// | ||
|
||
/* | ||
* Reverses a string inline recursively | ||
* @param {String} str - The string to be reversed | ||
* @returns {String} The reversed string | ||
*/ | ||
reverseString: function(str) { | ||
var len = str.length; | ||
if (len > 1) { | ||
return str[len - 1] + arguments.callee(str.substring(1, len - 1)) + str[0]; | ||
} | ||
return str; | ||
} | ||
}; | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = Strings_1_3 = (function() { | ||
return { | ||
// Tests to see if two strings are permutations of one another | ||
// Solution #2 from the book. Assumes ascii character set | ||
// @param {String} s - The first string | ||
// @param {String} t - The second string | ||
// @retuns {Boolean} - true if the strings are permutations of one another, false otherwise | ||
isPermutation: function(s, t) { | ||
|
||
var sLength = s.length; | ||
var tLength = t.length; | ||
|
||
if (sLength !== tLength) { | ||
return false; | ||
} | ||
|
||
var s_array = Array.apply(null, Array(256)).map(Number.prototype.valueOf, 0); | ||
|
||
for (var i = 0; i < sLength; i++) { | ||
s_array[s[i].charCodeAt(0)]++; | ||
} | ||
|
||
for (var i = 0; i < tLength; i++) { | ||
if (--s_array[t[i].charCodeAt(0)] < 0){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
}; | ||
}()); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.