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

Commit 8f27415

Browse files
committed
Added first test since it was a pain to debug, rewrite next highest number solution - closes #36 and #37. Adding testing and linting, will start adding tests for any new problems and wil go back and add tests as I have time.
1 parent ddfb11e commit 8f27415

58 files changed

Lines changed: 223 additions & 99 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
node_modules

.jshintignore

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

.jshintrc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"jquery": true,
5+
"devel": true,
6+
"nonstandard": true,
7+
"worker": true,
8+
"esnext": true,
9+
"bitwise": false,
10+
"boss": true,
11+
"camelcase": true,
12+
"curly": true,
13+
"eqeqeq": true,
14+
"eqnull": true,
15+
"expr": true,
16+
"forin": true,
17+
"immed": true,
18+
"latedef": true,
19+
"newcap": true,
20+
"noarg": true,
21+
"quotmark": "single",
22+
"regexp": true,
23+
"strict": false,
24+
"undef": true,
25+
"unused": true,
26+
"trailing": true,
27+
"smarttabs": true,
28+
"immed": true,
29+
"globals": {
30+
"it": true,
31+
"describe": true
32+
}
33+
}

Readme.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
# Code Problems
22

3-
This repo is full of code problems that I have received prior or during an interview. I'll present all my solutions here in JavaScript, but feel free to add your own solutions in another language and even optimise my solutions. If you have your own code problems you would like to contribute, I would love to see them as well.
3+
This is my repo full of code problems that I have completed prior to or during an interview. I hope that all these problems (and solutions) are useful to practice against and review. Feel free to contribute any solutions and optimisations, given they are algorithmic optimisations. Please add your own problems that you find as well, as I would love to see them.
4+
5+
## Contributing
6+
7+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
8+
9+
Lint and test your code using any means applicable, in JavaScript this means JSHint and Mocha which is run using Nodejs.
10+
11+
## Testing
12+
13+
```sh
14+
npm install # Installs `mocha` and any other dependencies needed to run
15+
npm test # Runs the testing scripts
16+
```

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

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

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

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

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;

byte-string/byte-string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var byteString = function (bytes, precision) {
1+
module.exports = function (bytes, precision) {
22
var suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
33
factor = Math.pow(10, precision > 0 ? precision : 2);
44
// Using a for loop since it's perfect for this kind of problem
5-
for (var i = bytes, k = 0; i >= 1024 && k < suffixes.length; i /= 1024, k++);
5+
for (var i = bytes, k = 0; i >= 1024 && k < suffixes.length; i /= 1024, k++) {}
66
// Return the number rounded to precision
77
return (Math.round(i * factor) / factor) + ' ' + suffixes[k];
88
};

0 commit comments

Comments
 (0)