Skip to content

Commit

Permalink
Merge pull request #124 from dawsonbotsford/master
Browse files Browse the repository at this point in the history
Removed node_modules and completed 1_2 and 1_3
  • Loading branch information
gaylemcd committed Sep 15, 2015
2 parents 20fd491 + bf2bddc commit f345d43
Show file tree
Hide file tree
Showing 270 changed files with 94 additions and 71,382 deletions.
27 changes: 27 additions & 0 deletions javascript/lib/data-structures/chapter-1/1_2.js
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;
}
};
}());
31 changes: 31 additions & 0 deletions javascript/lib/data-structures/chapter-1/1_3.js
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;
}
};
}());
1 change: 0 additions & 1 deletion javascript/node_modules/.bin/_mocha

This file was deleted.

1 change: 0 additions & 1 deletion javascript/node_modules/.bin/mocha

This file was deleted.

14 changes: 0 additions & 14 deletions javascript/node_modules/chai/.npmignore

This file was deleted.

206 changes: 0 additions & 206 deletions javascript/node_modules/chai/CONTRIBUTING.md

This file was deleted.

Loading

0 comments on commit f345d43

Please sign in to comment.