|
2 | 2 |
|
3 | 3 | You're here to solidify your understanding of recursion -- a fundamental programming concept -- in JavaScript.
|
4 | 4 |
|
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 | + |
| 93 | + |
| 94 | +#### Passing Tests Example |
| 95 | + |
| 96 | + |
| 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. |
0 commit comments