Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 524cf0f

Browse files
committed
Moving problems into a subdirectory.
1 parent dc7ad3c commit 524cf0f

File tree

200 files changed

+215
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+215
-558
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "test/cpp/gtest"]
2-
path = test/cpp/gtest
1+
[submodule "tests/cpp/gtest"]
2+
path = tests/cpp/gtest
33
url = [email protected]:tclamb/gtest.git

.jshintignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
node_modules
2-
3-
# Pretty dodgy JS to keep it so small
4-
shortest-fizz-buzz
2+
problems/shortest-fizz-buzz

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
SHELL := /bin/sh
2-
TEST_DIR := test
1+
SHELL := /bin/sh
2+
TEST_DIR := tests
33
GTEST_DIR := $(TEST_DIR)/cpp/gtest
44

55

@@ -32,8 +32,8 @@ all: .IGNORE
3232

3333

3434
# C++ build rules
35+
OTHER_SOURCES := $(TEST_DIR)/cpp/common.cpp
3536
FUSED_GTEST_SOURCES := $(GTEST_DIR)/gtest-all.cc $(GTEST_DIR)/gtest_main.cc
36-
OTHER_SOURCES := $(TEST_DIR)/cpp/common.cpp
3737
CXXFLAGS += -DGTEST_HAS_PTHREAD=0 -DGTEST_HAS_TR1_TUPLE=0 -g
3838
CPP_OBJECTS := $(CPP_SOURCES:.cpp=.o)
3939
FUSED_GTEST_OBJECTS := $(FUSED_GTEST_SOURCES:.cc=.o)

Readme.md

Lines changed: 11 additions & 19 deletions

kth-largest-element-in-array/kth-largest-element-in-array.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

longest-words/Readme.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

median-integer-stream/median-integer-stream.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"jshint": "~2.1.3"
1414
},
1515
"scripts": {
16-
"test": "./node_modules/.bin/mocha test/javascript && ./node_modules/.bin/jshint ."
16+
"lint": "./node_modules/.bin/jshint .",
17+
"test": "npm run lint && ./node_modules/.bin/mocha tests/javascript"
1718
},
1819
"repository": {
1920
"type": "git",
@@ -27,7 +28,7 @@
2728
],
2829
"author": "Blake Embrey",
2930
"license": "MIT",
30-
"readmeFilename": "Readme.md",
31+
"readmeFilename": "README.md",
3132
"bugs": {
3233
"url": "https://github.com/blakeembrey/code-problems/issues"
3334
}

anagram-detection/anagram-detection.js renamed to problems/anagram-detection/anagram-detection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var hashString = function (str) {
6161
}, 1);
6262
};
6363

64-
var anagramDetection = function (parent, child) {
64+
module.exports = function (parent, child) {
6565
var length = child.length,
6666
anagram = hashString(child),
6767
total = 0;

array-pair-sum/array-pair-sum.js renamed to problems/array-pair-sum/array-pair-sum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This is just a modification of the integer difference problem presented elsewhere
2-
var arrayPairSum = function (k, array) {
2+
module.exports = function (k, array) {
33
var hash = {},
44
pairs = [];
55

balanced-brackets/balanced-brackets.js renamed to problems/balanced-brackets/balanced-brackets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var brackets = {
66
};
77

88
// On each input string, process it using the balance checker
9-
var balancedBrackets = function (string) {
9+
module.exports = function (string) {
1010
var stack = [];
1111
// Process every character on input
1212
for (var i = 0; i < string.length; i++) {

binary-search-tree-check/binary-search-tree-check.js renamed to problems/binary-search-tree-check/binary-search-tree-check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var isBinarySearchTree = function isBST (bst) {
1+
module.exports = function isBST (bst) {
22
var test;
33

44
// Break the recursion if the left or right node is bigger than the current
File renamed without changes.

bubble-sort/bubble-sort.js renamed to problems/bubble-sort/bubble-sort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var bubbleSort = function (array, compare) {
1+
module.exports = function (array, compare) {
22
// Not an array, empty or array of 1 is already sorted
33
if (!Array.isArray(array) || array.length < 2) {
44
return array;
File renamed without changes.
File renamed without changes.

combine-two-strings/combine-two-strings.js renamed to problems/combine-two-strings/combine-two-strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var combineTwoStrings = function (str1, str2, combined) {
1+
module.exports = function (str1, str2, combined) {
22
// Generate all the posible paths between `str1` and `str2`
33
var paths = {};
44

convert-array/Readme.md renamed to problems/convert-array/Readme.md

Lines changed: 1 addition & 1 deletion

csv-parsing/csv-parsing.js renamed to problems/csv-parsing/csv-parsing.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
// Elegant solution using built-in JavaScript functions
2-
var parseCSV = function (csv) {
3-
return JSON.parse('[' + csv + ']');
4-
};
5-
6-
// Crazy parser which was the original solution
7-
var parseCSV = function (csv) {
1+
// Please note: This can be accomplished using `JSON.parse('[' + csv + ']')`
2+
module.exports = function (csv) {
83
var isNumber = false,
94
isInput = false,
105
curr = '',
File renamed without changes.
File renamed without changes.

even-occuring-element/even-occuring-element.js renamed to problems/even-occuring-element/even-occuring-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var evenOccuringElement = function (array) {
1+
module.exports = function (array) {
22
var hash = {};
33

44
// Loop though the array adding all the elements together in a hash
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

fibonacci/fibonnaci.js renamed to problems/fibonacci/fibonnaci.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Implementing recursive solution
2-
var fibonacci = function (n) {
2+
exports.recursive = function fibonacci (n) {
33
if (n in fibonacci) { return fibonacci[n]; }
44
// Store the fibonacci values on the function itself
55
return fibonacci[n] = (n < 2) ? n : fibonacci(n - 1) + fibonacci(n - 2);
66
};
77

88
// Implementing iterative solution
9-
var fibonacci = function (n) {
9+
exports.iterative = function fibonacci (n) {
1010
var results = [0, 1];
1111

1212
if (n > 2) {
@@ -19,7 +19,7 @@ var fibonacci = function (n) {
1919
};
2020

2121
// Implementing O(logn) matrix solution
22-
var fibonacci = function (n) {
22+
exports.matrix = function (n) {
2323
var memo = [0, [[0, 1], [1, 1]]];
2424

2525
var matrixMultiply = function (A, B) {

find-missing-element/find-missing-element.js renamed to problems/find-missing-element/find-missing-element.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Simple solution using a hash to look up numbers from the second array in the
22
// first array. When the number doesn't exist in the hash - you know we have
33
// found the missing number
4-
var findMissingElement = function (a, b) {
4+
exports.iterative = function (a, b) {
55
var hash = {}, i;
66

77
for (i = 0; i < b.length; i++) {
@@ -18,7 +18,7 @@ var findMissingElement = function (a, b) {
1818

1919
// Bitwise solution using XOR to cancel each of the corresponding numbers out
2020
// with eachother until we end up with a number that isn't cancelled out
21-
var findMissingElement = function (a, b) {
21+
exports.bitwise = function (a, b) {
2222
var result = 0;
2323
a.concat(b).forEach(function (num) {
2424
result ^= num;
@@ -28,7 +28,7 @@ var findMissingElement = function (a, b) {
2828

2929
// Maybe the simplest solution, but you can very easily add the two arrays and
3030
// take the result of `b` away from `a` to get the missing number
31-
var findMissingElement = function (a, b) {
31+
exports.sum = function (a, b) {
3232
var add = function (a, b) {
3333
return a + b;
3434
};

first-non-repeated-character/first-non-repeated-character.js renamed to problems/first-non-repeated-character/first-non-repeated-character.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var firstNonRepeatedCharacter = function (string) {
1+
module.exports = function (string) {
22
var checkChar,
33
prevCharacter;
44

flatten-array/flatten-array.js renamed to problems/flatten-array/flatten-array.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Create a new flattened array
2-
var flatten = function (input) {
2+
exports.newArray = function flatten (input) {
33
var output = [];
44

55
for (var i = 0; i < input.length; i++) {
6-
// Using Array.isArray for new browsers, in older browsers this can be
7-
// polyfilled using `Object.prototype.toString.call(input[i]) === '[object Array]'`
6+
// Using Array.isArray for new browsers, in older browsers this can be done
7+
// using `Object.prototype.toString.call(input[i]) === '[object Array]'`
88
if (Array.isArray(input[i])) {
99
output.push.apply(output, flatten(input[i]));
1010
} else {
@@ -16,7 +16,7 @@ var flatten = function (input) {
1616
};
1717

1818
// In place array flatten
19-
var flatten = function (array) {
19+
exports.inPlace = function (array) {
2020
var i = 0;
2121

2222
while (i < array.length) {
@@ -31,7 +31,7 @@ var flatten = function (array) {
3131
};
3232

3333
// Flatten array using ES5 reduce method
34-
var flatten = function (array) {
34+
exports.es5 = function flatten (array) {
3535
return array.reduce(function (arr, val) {
3636
return arr.concat(Array.isArray(val) ? flatten(val) : val);
3737
}, []);

get-elements-by-class-name/get-elements-by-class-name.js renamed to problems/get-elements-by-class-name/get-elements-by-class-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var getElementsByClassName = function (element, className) {
1+
exports.traversal = function (element, className) {
22
var found = [];
33

44
(function traverseDom (node) {
@@ -22,7 +22,7 @@ var getElementsByClassName = function (element, className) {
2222
return found;
2323
};
2424

25-
var getElementsByClassName = function (element, className) {
25+
exports.regexp = function (element, className) {
2626
// This function takes an easier approach, using a regular expression and
2727
// getting all elements straight up using the asterisk selector
2828
var found = [],
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)