Skip to content

Commit 10bc70a

Browse files
authored
Merge pull request #1 from hackreactor/workshop-content
Workshop content
2 parents df1ebf9 + 09aea65 commit 10bc70a

21 files changed

+25035
-1
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.eslint*
2+
**/node_modules
3+
**/bower_components
4+
**/lib
5+
**/vendor
6+
**/*.min.js

.eslintrc.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* These rules enforce Hack Reactor's style guide.
3+
* Visit this repo for more information:
4+
* https://github.com/reactorcore/eslint-config-hackreactor
5+
*/
6+
7+
module.exports = {
8+
env: {
9+
'es6': true
10+
},
11+
parserOptions: {
12+
ecmaFeatures: {
13+
'jsx': true
14+
}
15+
},
16+
rules: {
17+
/* Indentation */
18+
'no-mixed-spaces-and-tabs': 2,
19+
'indent': [2, 2],
20+
/* Variable cames */
21+
'camelcase': 2,
22+
/* Language constructs */
23+
'curly': 2,
24+
'eqeqeq': [2, 'smart'],
25+
'func-style': [2, 'expression'],
26+
/* Semicolons */
27+
'semi': 2,
28+
'no-extra-semi': 2,
29+
/* Padding & additional whitespace (perferred but optional) */
30+
'brace-style': [2, '1tbs', { 'allowSingleLine': true }],
31+
'semi-spacing': 1,
32+
'key-spacing': 1,
33+
'block-spacing': 1,
34+
'comma-spacing': 1,
35+
'no-multi-spaces': 1,
36+
'space-before-blocks': 1,
37+
'keyword-spacing': [1, { 'before': true, 'after': true }],
38+
'space-infix-ops': 1,
39+
/* Variable declaration */
40+
'one-var': [1, { 'uninitialized': 'always', 'initialized': 'never' }],
41+
/* Minuta */
42+
'comma-style': [2, 'last'],
43+
'quotes': [1, 'single']
44+
}
45+
};

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
### node etc ###
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# Compiled Dirs (http://nodejs.org/api/addons.html)
22+
build/
23+
dist/
24+
25+
# Dependency directorys
26+
# Deployed apps should consider commenting these lines out:
27+
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
28+
node_modules/
29+
bower_components/
30+
31+
# Floobits
32+
.floo
33+
.floobit
34+
.floo
35+
.flooignore

README.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,99 @@
22

33
You're here to solidify your understanding of recursion -- a fundamental programming concept -- in JavaScript.
44

5-
*IMPORTANT*: Completion of this workshop is no guarantee of admission into the Hack Reactor immersive program, nor does it have any influence in the admissions process.
5+
*IMPORTANT*: Completion of this workshop is no guarantee of admission into the Hack Reactor immersive program, nor does it have any influence in the admissions process.
6+
7+
## Prerequisites
8+
9+
This workshop is designed for folks in the midst of studying intermediate-level JavaScript who have a few months of foundational experience. You will be expected to understand the basics of the Document Object Model (DOM) as applied to HTML.
10+
11+
## Textbook
12+
13+
No textbook is required for this workshop. All materials are included in this GitHub repo.
14+
15+
## Technical requirements
16+
17+
Laptop, Google Chrome browser and a text editor. If you do not have a text editor, we recommend Visual Studio Code, Sublime Text, or Atom.
18+
19+
# How to use this repository
20+
21+
### Let's get started...
22+
23+
Run the SpecRunner.html file in a browser. This document current shows 4 failing tests.
24+
25+
- The `spec` folder holds all the failing tests that are being displayed in SpecRunner.html.
26+
- The `src` folder holds the functions that are being called to run the tests.
27+
- Your task is to edit the files in `src` to complete the functions and get the tests to pass.
28+
- These files are just javascript files so you can use `console.log` to help debug and inspect these functions.
29+
30+
## Recursion Review
31+
32+
Recursion is a technique for solving problems wherein a function makes calls to itself. By doing so, it can complete a small amount of the processing, and delegate the rest of the problem to the recursive calls.
33+
34+
Consider the following function:
35+
36+
```js
37+
var eat = function(meal){
38+
console.log('meal before bite:', meal);
39+
console.log('now eating', meal.pop());
40+
if(meal.length){
41+
eat(meal);
42+
} else {
43+
console.log('done with the meal!');
44+
}
45+
}
46+
```
47+
48+
Which produces this output:
49+
50+
```js
51+
eat(['soup', 'potatoes', 'fish']);
52+
// => meal before bite: ["soup", "potatoes", "fish"]
53+
// => now eating fish
54+
// => meal before bite: ["soup", "potatoes"]
55+
// => now eating potatoes
56+
// => meal before bite: ["soup"]
57+
// => now eating soup
58+
// => done with the meal!
59+
```
60+
61+
You can use recursion on problems where smaller parts of the problem look the same as the larger problem as a whole.
62+
63+
In this sprint, you'll be practicing writing recursive functions, building up to the reimplementation of a JavaScript browser method that involves recursion (getElementsByClassName). In so doing, don't use the things you're reimplementing, or any other built-in shortcuts that make these problems trivial. (You'll probably know if you're cheating, but feel free to ask us if you're not sure.)
64+
65+
(Curious fact: many browsers don't have any of these functions in them, and people do need to reimplement them. When we reimplement new browser functionality in older browsers, it's called a "polyfill".)
66+
67+
## Exercises
68+
69+
More detailed instructions and examples for each exercise can be found in the individual `.js` files in the `src` folder.
70+
71+
### 1: sumArray
72+
73+
- [ ] Implement `sumArray` with your own code in `src/sumArray.js`
74+
75+
### 2: power
76+
77+
- [ ] Implement `power` with your own code in `src/power.js`
78+
79+
### 3: nthFibonacci
80+
81+
- [ ] Implement `nthFibonacci` with your own code in `src/nthFibonacci.js`
82+
83+
### 4: getElementsByClassName
84+
85+
- [ ] Implement `getElementsByClassName` with your own code in `src/getElementsByClassName.js`
86+
- [ ] You should use `document.body`, `element.childNodes`, and `element.classList`
87+
- NOTE: You may also use methods from the [underscore](https://underscorejs.org) library for assitance, but are not required to do so.
88+
- You can view the MDN documentation for getElementsByClassName [here](https://developer.mozilla.org/en/docs/Web/API/Document/getElementsByClassName)
89+
90+
#### Failing Tests Example
91+
92+
![failing tests](images/failing-tests.png)
93+
94+
#### Passing Tests Example
95+
96+
![passing tests](images/passing-tests.png)
97+
98+
### Don't forget..
99+
100+
You should throroughly read all of code in front of you and aim to understand line-by-line what is happening.

SpecRunner.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>Mocha Spec Runner</title>
5+
<link rel="stylesheet" href="lib/mocha/mocha.css">
6+
<script src="lib/jquery.js"></script>
7+
<script src="lib/underscore.js"></script>
8+
<script src="lib/mocha/mocha.js"></script>
9+
<script src="lib/chai/chai.js"></script>
10+
<script src="lib/sinon/sinon.js"></script>
11+
<script>
12+
mocha.setup({ui: 'bdd'});
13+
window.expect = chai.expect;
14+
$(function() {
15+
window.mochaPhantomJS ? mochaPhantomJS.run() : mocha.run();
16+
});
17+
</script>
18+
<script src="src/sumArray.js"></script>
19+
<script src="src/power.js"></script>
20+
<script src="src/nthFibonacci.js"></script>
21+
<script src="src/getElementsByClassName.js"></script>
22+
<script src="spec/sumArraySpec.js"></script>
23+
<script src="spec/powerSpec.js"></script>
24+
<script src="spec/nthFibonacciSpec.js"></script>
25+
<script src="spec/getElementsByClassNameSpec.js"></script>
26+
</head>
27+
<body>
28+
<div id="mocha"></div>
29+
</body>
30+
</html>
31+

images/failing-tests.png

149 KB
Loading

images/passing-tests.png

78.4 KB
Loading

0 commit comments

Comments
 (0)