You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: coderoad.json
+30-22Lines changed: 30 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@
10
10
{
11
11
"title": "Filter",
12
12
"description": "Array -> Array of items that match a condition",
13
-
"explanation": "You've hacked into the school's computer system, and just in time. The grades are in, aren't you're not too proud of your performance. But that's okay, you have a plan: you're going to create a fake report card.\n\nIt would be great if you could `filter` the scores that your parents will see. A `filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:\n\n```\nfunction isA(x) {\n return x === 'a';\n}\n```\n\n\nLike all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one.\n\n```\nvar list = ['a', 'b'];\nlist.filter(isA);\n\n// if isA(list[0]), add to output array\n// if isA(list[1]), add to output array\n//\n//> ['a']\n```\n\nIf your data was composed of objects, we could use dot notation to find matches. Checkout `isB` below.\n\n```\nfunction isB(x) {\n return x.item === 'b'\n}\n\nvar list = [{item: 'a'}, {item: 'b'}];\nlist.filter(isB);\n//> [{item: 'b'}]\n```\n\nWhere were we? Back to filtering our grades.\n\nThere's too much student data in the computer system. We'll have to sort through it. Have a look at an example below:\n\n```\nconsole.log(data[0]);\n//> { course: 'Web Security',\n// instructor: 'Sue Denim',\n// name: 'Rebecca Heineman',\n// score: 93,\n// grade: 'A' }\n```",
13
+
"explanation": "You've hacked into the school's computer system, and just in time. The grades are in, but you're not too proud of your performance. That's okay, you have a plan: you're going to create a fake report card.\n\nIt would be great if you could `filter` the scores that your parents will see.\n\n`filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:\n\n```\nfunction isA(x) {\n return x === 'a';\n}\n```\n\n\nLike all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one. [Learn more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).\n\n```\nvar list = ['a', 'b'];\nlist.filter(isA);\n\n// if isA(list[0]), add to output array\n// if isA(list[1]), add to output array\n//\n//> ['a']\n```\n\nIf your data was composed of objects, we could use dot notation to find matches. Checkout `isB` below.\n\n```\nfunction isB(x) {\n return x.item === 'b'\n}\n\nvar list = [{item: 'a'}, {item: 'b'}];\nlist.filter(isB);\n//> [{item: 'b'}]\n```\n\nWhere were we? Back to filtering our grades.\n\nThere's too much student data in the computer system. We'll have to sort through it. Have a look at an example below:\n\n```\nconsole.log(data[0]);\n//> { course: 'Web Security',\n// instructor: 'Sue Denim',\n// name: 'Rebecca Heineman',\n// score: 93,\n// grade: 'A' }\n```",
14
14
"tasks": [
15
15
{
16
16
"description": "Write a filter condition function called `isAda` that returns true only if the name matches your name: \"Ada Lovelace\".",
@@ -55,7 +55,7 @@
55
55
{
56
56
"title": "Sort",
57
57
"description": "Array -> sorted Array",
58
-
"explanation": "Your grades are filtered down to your name and good scores - but wouldn't it be better if your best grades were shown at the top? Besides, your parents rarely read all the way down to the bottom.\n\nWe can use the array method `sort` to arrange our data. Let's see how it works.\n\n```js\n['c', 'b', 'a'].sort();\n//> ['a', 'b', 'c']\n\n[3, 2, 1].sort();\n//> [1, 2, 3]\n```\n\nBut what about sorting the scores inside of an object? We can write a custom `compareScore` function.\n\nA sort function takes two params, and compares the first to the second. It should return values saying where the second value should go:\n\n * -1 : sort to a lower index\n * 1 : sort to a higher index\n * 0 : stay the same\n\nAlright, now time to sort your best grades to the top.",
58
+
"explanation": "Your grades are filtered down to your name and good scores - but wouldn't it be better if your best grades were displayed first, at the top? Besides, your parents rarely read anything through.\n\nYou can use the array method `sort` to arrange your data. Let's see how it works.\n\n```js\n['c', 'b', 'a'].sort();\n//> ['a', 'b', 'c']\n\n[3, 2, 1].sort();\n//> [1, 2, 3]\n```\n\nBut what about sorting scores inside of an object?\n\n```js\n[{a: 3}, {a: 1}, {a: 2}].sort();\n//> [{a: 3}, {a: 1}, {a: 2}]\n```\n\nThat didn't work. Instead, you can write a custom `compareScore` function.\n\nA sort function takes two params, and compares the first to the second. It should return values saying where the second value should go in the array:\n\n * -1 : sort to a lower index (front)\n * 1 : sort to a higher index (back)\n * 0 : stay the same\n\nAlright, now time to sort your best grades to the top.",
59
59
"tasks": [
60
60
{
61
61
"description": "Write a sort condition function called `compareScore` that can sort your data by score.",
@@ -68,7 +68,7 @@
68
68
]
69
69
},
70
70
{
71
-
"description": "Set `mySortedGrades` to `myBest` data sorted with `compareScore`",
71
+
"description": "Set `mySortedGrades` to `myBest` data sorted by `compareScore`",
72
72
"tests": [
73
73
"1/02/01-sort"
74
74
],
@@ -178,14 +178,14 @@
178
178
"explanation": "Somehow your name has disappeared from the computer system. We'll have to `find` a way to get it back.\n\nYou quickly put together a list of other students in class. If someone changed your name, it'll be the name that is not in that list.\n\n`find` works similar to `filter`, but returns only the first match.\n\n```\nvar data = [1, 2, 3, 4, 5, 6];\n\nfunction isEven(num) {\n return num % 2 === 0;\n}\n\n// returns all matching data to a condition\ndata.filter(isEven);\n//> [2, 4, 6]\n\n// returns the first match\ndata.find(isEven);\n//> [2]\n```\n\nFind is great for performantly matching unique values in data, such as \"id\"'s, or in our case, names.",
179
179
"tasks": [
180
180
{
181
-
"description": "`filter` down students in the class titled Web Security (`{ title: \"Web Security\" }`)",
181
+
"description": "`filter` to students in the class titled \"Web Security\"",
"description": "Use `reduce` to calculate the class average",
286
+
"description": "Use `reduce` to sum the numbers in the `practice` array",
287
287
"tests": [
288
288
"1/07/01-reduce"
289
289
],
290
290
"actions": [
291
-
"open('07-reduce.js')"
291
+
"open('07-reduce.js')",
292
+
"set('var practice = [1, 1, 2, 3, 5, 8, 13, 21];\n\n// total the numbers using a reduce function\n// hint: start at 0\nvar total = practice.reduce();\n')"
292
293
]
293
294
},
294
295
{
295
-
"description": "`reduce` to suspect scores",
296
+
"description": "`map` over each course and use `reduce` to calculate the class averages for each class. Set `averages` to the resulting array of all class averages.",
296
297
"tests": [
297
298
"1/07/02-reduce"
299
+
],
300
+
"actions": [
301
+
"insert('// Remember, an average is the sum of all student scores divided by the number of students\n// set the result to an array, for example: [50, 65, 75, 85, ...];\nvar averages = courses.reduce();\n')"
298
302
]
299
303
},
300
304
{
301
-
"description": "`map` over suspect data to find the score differences",
305
+
"description": "`reduce` to an array of suspect scores",
"description": "`reduce` down to likely suspect names",
314
+
"description": "`map` over suspect data to find the `\"difference\"` from subtracting the students score from the average score. Add this to `suspectScores` using the key `difference`. The resulting array should look like this:\n```js\n[{\n name: 'suspectName',\n scores: [50, 65, 75, 85...],\n difference: 15\n}]\n```",
308
315
"tests": [
309
316
"1/07/04-reduce"
310
317
]
318
+
},
319
+
{
320
+
"description": "`reduce` down to any likely suspect names by filtering with the `isCheater` function",
321
+
"tests": [
322
+
"1/07/05-reduce"
323
+
],
324
+
"actions": [
325
+
"insert('\nfunction isCheater(suspect) {\n return suspect.difference > 200;\n}\n\n// reduce down to a string of likely suspects\nvar likelySuspect = suspectScores.reduce().join(', ');\nconsole.log(likelySuspect);\n')"
326
+
]
311
327
}
312
328
]
313
-
},
314
-
{
315
-
"title": "Challenge 1",
316
-
"description": "coming soon"
317
-
},
318
-
{
319
-
"title": "Challenge 2",
320
-
"description": "coming soon"
321
329
}
322
330
],
323
-
"description": "Using common built-in Javascript array methods such as `map` & `reduce`.\n\nBy the end, you should have an understanding of how to use array methods to manipulate semi-complex data."
331
+
"description": "Using common built-in Javascript array methods such as `map` & `reduce`.\n\nBy the end, you should have an understanding of how to use array methods to manipulate semi-complex data.\n\n<!-- @import('./tutorial/1/08/challenge-1') -->\n<!-- @import('./tutorial/1/09/challenge-2') -->"
Copy file name to clipboardExpand all lines: tutorial/1/01/filter.md
+5-3Lines changed: 5 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
### Filter
2
2
Array -> Array of items that match a condition
3
3
4
-
You've hacked into the school's computer system, and just in time. The grades are in, aren't you're not too proud of your performance. But that's okay, you have a plan: you're going to create a fake report card.
4
+
You've hacked into the school's computer system, and just in time. The grades are in, but you're not too proud of your performance. That's okay, you have a plan: you're going to create a fake report card.
5
5
6
-
It would be great if you could `filter` the scores that your parents will see. A `filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:
6
+
It would be great if you could `filter` the scores that your parents will see.
7
+
8
+
`filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:
7
9
8
10
```
9
11
function isA(x) {
@@ -12,7 +14,7 @@ function isA(x) {
12
14
```
13
15
14
16
15
-
Like all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one.
17
+
Like all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one.[Learn more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
Copy file name to clipboardExpand all lines: tutorial/1/02/sort.md
+14-7Lines changed: 14 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
### Sort
2
2
Array -> sorted Array
3
3
4
-
Your grades are filtered down to your name and good scores - but wouldn't it be better if your best grades were shown at the top? Besides, your parents rarely read all the way down to the bottom.
4
+
Your grades are filtered down to your name and good scores - but wouldn't it be better if your best grades were displayed first, at the top? Besides, your parents rarely read anything through.
5
5
6
-
We can use the array method `sort` to arrange our data. Let's see how it works.
6
+
You can use the array method `sort` to arrange your data. Let's see how it works.
7
7
8
8
```js
9
9
['c', 'b', 'a'].sort();
@@ -13,12 +13,19 @@ We can use the array method `sort` to arrange our data. Let's see how it works.
13
13
//> [1, 2, 3]
14
14
```
15
15
16
-
But what about sorting the scores inside of an object? We can write a custom `compareScore` function.
16
+
But what about sorting scores inside of an object?
17
17
18
-
A sort function takes two params, and compares the first to the second. It should return values saying where the second value should go:
18
+
```js
19
+
[{a:3}, {a:1}, {a:2}].sort();
20
+
//> [{a: 3}, {a: 1}, {a: 2}]
21
+
```
22
+
23
+
That didn't work. Instead, you can write a custom `compareScore` function.
24
+
25
+
A sort function takes two params, and compares the first to the second. It should return values saying where the second value should go in the array:
19
26
20
-
* -1 : sort to a lower index
21
-
* 1 : sort to a higher index
27
+
* -1 : sort to a lower index (front)
28
+
* 1 : sort to a higher index (back)
22
29
* 0 : stay the same
23
30
24
31
Alright, now time to sort your best grades to the top.
@@ -44,7 +51,7 @@ function compareScore(a, b) {
44
51
```
45
52
))
46
53
47
-
+ Set `mySortedGrades` to `myBest` data sorted with`compareScore`
54
+
+ Set `mySortedGrades` to `myBest` data sorted by`compareScore`
0 commit comments