Skip to content

Commit ff85bbc

Browse files
Initial commit of my answers to JS Assessment
0 parents  commit ff85bbc

36 files changed

+1435
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
npm-debug.log
2+
node_modules/
3+
.idea

.jshintrc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"node" : true,
3+
"browser" : true,
4+
5+
"boss" : false,
6+
"curly": false,
7+
"debug": false,
8+
"devel": false,
9+
"eqeqeq": true,
10+
"evil": true,
11+
"forin": false,
12+
"immed": true,
13+
"laxbreak": false,
14+
"newcap": true,
15+
"noarg": true,
16+
"noempty": false,
17+
"nonew": false,
18+
"nomen": false,
19+
"plusplus": false,
20+
"regexp": false,
21+
"undef": true,
22+
"sub": true,
23+
"strict": false,
24+
"quotmark": "single",
25+
26+
"predef": [
27+
"describe",
28+
"beforeEach",
29+
"afterEach",
30+
"it",
31+
"arraysAnswers",
32+
"asyncAnswers",
33+
"bestPracticesAnswers",
34+
"countAnswers",
35+
"flowControlAnswers",
36+
"functionsAnswers",
37+
"logicalOperatorsAnswers",
38+
"modulesAnswers",
39+
"numbersAnswers",
40+
"objectsAnswers",
41+
"recursionAnswers",
42+
"regexAnswers"
43+
]
44+
}

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Change Log
2+
3+
## 0.3.0
4+
5+
- Remove jquery, backbone, underscore, mocha, and chai as local libraries
6+
- Remove RequireJS
7+
- node deps use native `require()`
8+
- browser deps are `script` tags
9+
10+
## 0.2.0
11+
12+
- Convert app from Express to using serve-static
13+
- Replace bin/server with a `grunt connect` task and `npm start` script
14+
- Update dependencies
15+
16+
## < 0.1.0
17+
18+
- Initial commits. Hello World!

Gruntfile.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = function(grunt) {
2+
require('load-grunt-tasks')(grunt);
3+
4+
grunt.initConfig({
5+
jshint: {
6+
all: [
7+
'app/**/*.js',
8+
'tests/app/**/*.js',
9+
'tests/runner.js',
10+
'Gruntfile.js',
11+
'!app/bestPractices.js'
12+
],
13+
options: {
14+
jshintrc: '.jshintrc'
15+
}
16+
},
17+
watch: {
18+
scripts: {
19+
files: ['app/**/*.js', 'tests/app/**/*.js'],
20+
tasks: ['jshint'],
21+
options: {
22+
livereload: true
23+
}
24+
}
25+
},
26+
connect: {
27+
server: {
28+
options: {
29+
port: 4444,
30+
base: {
31+
path: __dirname,
32+
options: {
33+
index: 'tests/runner.html',
34+
keepalive: true
35+
}
36+
}
37+
}
38+
}
39+
}
40+
});
41+
42+
grunt.registerTask('default', [ 'jshint' ]);
43+
grunt.registerTask('develop', [ 'connect', 'watch' ]);
44+
};

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# A test-driven JS assessment
2+
3+
[![Join the chat at https://gitter.im/rmurphey/js-assessment](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rmurphey/js-assessment?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
5+
This repo includes a set of tests that can be used to assess the skills of
6+
a candidate for a JavaScript position, or to improve one's own skills.
7+
8+
## I want to work on the tests; what do I do?
9+
To use the tests, you will need to install Node -- you can do this via the
10+
[download page](https://nodejs.org/download/) or using
11+
[Homebrew](http://mxcl.github.com/homebrew/) if you are on a Mac.
12+
13+
Note that on Windows, there are some reports that you will need to restart
14+
after installing Node - see #12.
15+
16+
You can clone or download this repo. Once you have done so, from the root
17+
directory of the repo, run:
18+
19+
npm install
20+
npm start
21+
22+
You can then view the tests in your browser at
23+
[http://localhost:4444](http://localhost:4444).
24+
25+
When you visit that page, all of the tests should be failing; your job is to
26+
get the tests to pass. To do this, you'll need to refer to the tests in the
27+
files in the `tests/app` directory, and edit the files in the `app/` directory.
28+
Once you update a test, you can reload the test page in the browser to see
29+
whether it worked.
30+
31+
You can also run (most of) the tests on the command line:
32+
33+
npm test
34+
35+
The command line runner is a work in progress; contributions welcome :)
36+
37+
You can also develop with live-reload and grunt-watch if that's your thing:
38+
39+
npm install -g grunt-cli
40+
npm install
41+
grunt develop
42+
43+
## I need help!
44+
45+
There may be friendly folks willing to help you in \#js-assessment or
46+
\#jshotline on freenode IRC.
47+
48+
## I want to contribute tests; what do I do?
49+
50+
Submit a pull request! The tests are currently loosely organized by topic, so
51+
you should do your best to add tests to the appropriate file in `tests/app`, or
52+
create a new file there if you don't see an appropriate one. If you do create
53+
a new file, make sure to add it to `tests/runner.js`, and to add a stub for the
54+
solution to the corresponding file in `app/`. Finally, it would be great if you
55+
could update the [answers](https://github.com/rmurphey/js-assessment-answers)
56+
as well.
57+
58+
Any substantial contributions will be duly credited in the readme, as well as
59+
of course in the git commit log.
60+
61+
### Data-driven tests
62+
63+
If your tests need data that can be fetched via XHR, stick a `.json` file in
64+
the `data` directory; you can access it at `/data/<filename>.json`.
65+
66+
### Available dependencies
67+
68+
The repo includes jQuery, Backbone, and Underscore. Do take advantage of these
69+
libraries when writing your solutions!
70+
71+
## I want to see the answers!
72+
73+
First, bear in mind that looking up the answers is going to teach you a whole
74+
lot less than you'll learn by working on the tests, even if you occasionally get
75+
stuck. I'd recommend only looking at the answers once you have the tests
76+
passing, to see if there's another way you could have approached the
77+
problem. When you're ready to look at the answers, you can find them
78+
[here](https://github.com/rmurphey/js-assessment-answers); I'll do my best to
79+
keep them up to date.
80+
81+
## I hate \<some technology you've chosen\>
82+
83+
This repo uses [Mocha](http://visionmedia.github.com/mocha/) and
84+
[Chai](http://chaijs.com/) for the tests themselves. It uses the BDD style for authoring tests.
85+
If this doesn't suit you, please fork away, or, better, submit a pull request that lets
86+
this be more flexible than it currently is.
87+
88+
# Todos
89+
90+
There are a number of things that would make this project better; check out the
91+
[issues](https://github.com/rmurphey/js-assessment/issues) for details, pull
92+
requests welcome!
93+
94+
# License
95+
96+
Copyright &copy; 2012-2015 Rebecca Murphey.
97+
98+
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a>
99+
100+
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.

app/arrays.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
exports = (typeof window === 'undefined') ? global : window;
2+
3+
exports.arraysAnswers = {
4+
5+
indexOf : function(arr, item) {
6+
7+
},
8+
9+
sum : function(arr) {
10+
11+
},
12+
13+
remove : function(arr, item) {
14+
15+
},
16+
17+
removeWithoutCopy : function(arr, item) {
18+
19+
},
20+
21+
append : function(arr, item) {
22+
23+
},
24+
25+
truncate : function(arr) {
26+
27+
},
28+
29+
prepend : function(arr, item) {
30+
31+
},
32+
33+
curtail : function(arr) {
34+
35+
},
36+
37+
concat : function(arr1, arr2) {
38+
39+
},
40+
41+
insert : function(arr, item, index) {
42+
43+
},
44+
45+
count : function(arr, item) {
46+
47+
},
48+
49+
duplicates : function(arr) {
50+
51+
},
52+
53+
square : function(arr) {
54+
55+
},
56+
57+
findAllOccurrences : function(arr, target) {
58+
59+
}
60+
};

app/async.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports = (typeof window === 'undefined') ? global : window;
2+
3+
exports.asyncAnswers = {
4+
async : function(value) {
5+
6+
},
7+
8+
manipulateRemoteData : function(url) {
9+
10+
}
11+
};

app/bestPractices.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
exports = (typeof window === 'undefined') ? global : window;
2+
3+
/**
4+
* This file defines an object with some methods. Some of these methods are
5+
* populated incorrectly; your job is to fix them. Other methods are not
6+
* populated at all; your job is to fill them out.
7+
*/
8+
9+
exports.bestPracticesAnswers = {
10+
globals : function() {
11+
myObject = {
12+
name : 'Jory'
13+
};
14+
15+
return myObject;
16+
},
17+
18+
functions : function(flag) {
19+
if (flag) {
20+
function getValue() { return 'a'; }
21+
} else {
22+
function getValue() { return 'b'; }
23+
}
24+
25+
return getValue();
26+
},
27+
28+
parseInt : function(num) {
29+
return parseInt(num);
30+
},
31+
32+
identity : function(val1, val2) {
33+
34+
}
35+
};

app/count.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exports = (typeof window === 'undefined') ? global : window;
2+
3+
exports.countAnswers = {
4+
count : function (start, end) {
5+
6+
}
7+
};

app/flowControl.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports = (typeof window === 'undefined') ? global : window;
2+
3+
exports.flowControlAnswers = {
4+
fizzBuzz : function(num) {
5+
// write a function that receives a number as its argument;
6+
// if the number is divisible by 3, the function should return 'fizz';
7+
// if the number is divisible by 5, the function should return 'buzz';
8+
// if the number is divisible by 3 and 5, the function should return
9+
// 'fizzbuzz';
10+
//
11+
// otherwise the function should return the number, or false if no number
12+
// was provided or the value provided is not a number
13+
14+
}
15+
};

0 commit comments

Comments
 (0)