Skip to content

Commit 22eda67

Browse files
committed
open console directions
1 parent 2390fec commit 22eda67

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

coderoad.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"actions": [
2121
"open('01-filter.js')",
22-
"set('/**\n * Data is set as a global. Example:\n * [{\n * \"title\": \"Relational Databases\",\n * \"instructor\": \"Sean Quentin Lewis\",\n * \"name\": \"Ada Lovelace\",\n * \"score\": 91,\n * \"grade\": \"A\"\n * },\n * ...\n * ]\n */\n')",
22+
"set('/**\n * Data is set as a global. Example:\n * [{\n * \"title\": \"Relational Databases\",\n * \"instructor\": \"Sean Quentin Lewis\",\n * \"name\": \"Ada Lovelace\",\n * \"score\": 91,\n * \"grade\": \"A\"\n * },\n * ...\n * ]\n*/\n')",
2323
"insert('function isAda() {\n // write condition here\n // return true if student name\n // matches \"Ada Lovelace\"\n\n}\n')"
2424
]
2525
},
@@ -152,7 +152,7 @@
152152
{
153153
"title": "forEach",
154154
"description": "Array -> run a function for each item",
155-
"explanation": "You've updated your grades, but they're still in an array. It's time to loop over them and log them to the console.\n\n`forEach` has a lot in common with `map`, but there is a big difference. Understanding that difference is important for grasping the difference between:\n\n * **functional** & **imperative** programming\n * **pure** & **impure** functions\n\nKnow it or not, you're probably already used to \"imperative\" programming.\n\n> **Imperative** programming describes the order of actions\n\nImperative code tells the computer what to do, step by step.\n\n```js\nvar x = 1; // make a variable\nx = x + 1; // add one\nx = x + 1; // add another\nconsole.log(x);\n//> 3\n```\n\n> **Functional** programming describes the data transformation\n\nFunctional programming is a lot like writing math equations. As in math, 1 + 1 always equals 2.\n\nIn the same way, a **pure** function will always have the same result from a given input. Input 1 -> output 2. Every time.\n\n```js\n// a pure function\nfunction addOne(x) {\n return x + 1;\n}\naddOne(1)\n//> 2\naddOne(1)\n//> 2\n```\n\nA function is \"pure\" if it doesn't change anything outside of its scope. Pure functions are easy to test, reuse and reason about. In other words, they make your job easier.\n\nOn the other hand, **impure** functions are less predictable. The result may be different if you call it at a later time.\n\n```js\nvar y = 1;\n// impure function\nfunction increment(x) {\n y += x;\n return y;\n}\nincrement(1)\n//> 2\nincrement(1)\n//> 3\n```\n\nIt's good practice to ensure your `map` functions remain pure.\n\nBut `forEach` can be a little more dangerous. Why? Let's have a look.\n\n```js\n[1, 2, 3].map(addOne);\n//> [2, 3, 4]\n\n[1, 2, 3].forEach(addOne);\n//> undefined\n```\n\nWhat? `undefined`? `forEach` runs a function on each item in the array, and doesn't care what the function returns. Functions called by `forEach` must make changes, called **side effects**, to even be noticed.\n\n```js\n// impure function, changes log\nfunction addOneToLog(x) {\n console.log(x);\n}\n\n[1, 2, 3].forEach(addOneToLog);\n//> 2\n//> 3\n//> 4\n```\n\nNow that we see how `forEach` works, let's use it to make calls to the `console`.",
155+
"explanation": "You've updated your grades, but they're still in an array. It's time to loop over them and log them to the console.\n\nTo open the console, go to *View* > *Developer* > *Toggle Developer Tools*. Or press *cmd+opt+I* on Mac, *ctrl+alt+I* on Windows.\n\n`forEach` has a lot in common with `map`, but there is a big difference. Understanding that difference is important for grasping the difference between:\n\n * **functional** & **imperative** programming\n * **pure** & **impure** functions\n\nKnow it or not, you're probably already used to \"imperative\" programming.\n\n> **Imperative** programming describes the order of actions\n\nImperative code tells the computer what to do, step by step.\n\n```js\nvar x = 1; // make a variable\nx = x + 1; // add one\nx = x + 1; // add another\nconsole.log(x);\n//> 3\n```\n\n> **Functional** programming describes the data transformation\n\nFunctional programming is a lot like writing math equations. As in math, 1 + 1 always equals 2.\n\nIn the same way, a **pure** function will always have the same result from a given input. Input 1 -> output 2. Every time.\n\n```js\n// a pure function\nfunction addOne(x) {\n return x + 1;\n}\naddOne(1)\n//> 2\naddOne(1)\n//> 2\n```\n\nA function is \"pure\" if it doesn't change anything outside of its scope. Pure functions are easy to test, reuse and reason about. In other words, they make your job easier.\n\nOn the other hand, **impure** functions are less predictable. The result may be different if you call it at a later time.\n\n```js\nvar y = 1;\n// impure function\nfunction increment(x) {\n y += x;\n return y;\n}\nincrement(1)\n//> 2\nincrement(1)\n//> 3\n```\n\nIt's good practice to ensure your `map` functions remain pure.\n\nBut `forEach` can be a little more dangerous. Why? Let's have a look.\n\n```js\n[1, 2, 3].map(addOne);\n//> [2, 3, 4]\n\n[1, 2, 3].forEach(addOne);\n//> undefined\n```\n\nWhat? `undefined`? `forEach` runs a function on each item in the array, and doesn't care what the function returns. Functions called by `forEach` must make changes, called **side effects**, to even be noticed.\n\n```js\n// impure function, changes log\nfunction addOneToLog(x) {\n console.log(x);\n}\n\n[1, 2, 3].forEach(addOneToLog);\n//> 2\n//> 3\n//> 4\n```\n\nNow that we see how `forEach` works, let's use it to make calls to the `console`.",
156156
"tasks": [
157157
{
158158
"description": "Use `forEach` to log out your report card to the console",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-functional-school",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Coderoad tutorial",
55
"author": "Shawn McKay <shawn.j.mckay@gmail.com> (http://shmck.com)",
66
"contributers": [],
@@ -27,7 +27,7 @@
2727
"chai-spies": "0.7.1",
2828
"lodash": "4.5.0",
2929
"mocha": "2.4.5",
30-
"mocha-coderoad": "^0.4.0"
30+
"mocha-coderoad": "^0.4.1"
3131
},
3232
"license": "MIT",
3333
"config": {

tutorial/1/01/filter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ console.log(data[0]);
6767
* },
6868
* ...
6969
* ]
70-
*/
70+
*/
7171
```
7272
))
7373
@action(insert(

tutorial/1/04/forEach.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Array -> run a function for each item
33

44
You've updated your grades, but they're still in an array. It's time to loop over them and log them to the console.
55

6+
To open the console, go to *View* > *Developer* > *Toggle Developer Tools*. Or press *cmd+opt+I* on Mac, *ctrl+alt+I* on Windows.
7+
68
`forEach` has a lot in common with `map`, but there is a big difference. Understanding that difference is important for grasping the difference between:
79

810
* **functional** & **imperative** programming

0 commit comments

Comments
 (0)