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
+46-1Lines changed: 46 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,51 @@
7
7
{
8
8
"title": "Array Methods",
9
9
"pages": [
10
+
{
11
+
"title": "Filter",
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```",
14
+
"tasks": [
15
+
{
16
+
"description": "Write a filter condition function called `isAda` that returns true only if the name matches your name: \"Ada Lovelace\".",
17
+
"tests": [
18
+
"1/01/01-filter"
19
+
],
20
+
"actions": [
21
+
"open('01-filter.js')",
22
+
"set('function isAda(student) {\n // write condition here\n // the name must match \"Ada Lovelace\"\n\n}\n')"
23
+
]
24
+
},
25
+
{
26
+
"description": "Set `let myData` equal to data matching your name, \"Ada Lovelace\".",
27
+
"tests": [
28
+
"1/01/02-filter"
29
+
],
30
+
"actions": [
31
+
"insert('/**\n * Data is set as a global. Example:\n * [{\n * \"course\": \"Relational Databases\",\n * \"instructor\": \"Sean Quentin Lewis\",\n * \"name\": \"Ada Lovelace\",\n * \"score\": 91,\n * \"grade\": \"A\"\n * },\n * ...\n * ]\n */\n')",
"description": "Write a filter condition called `isGoodGrade` that will filter out any \"D\" or \"F\" grades.",
37
+
"tests": [
38
+
"1/01/03-filter"
39
+
],
40
+
"actions": [
41
+
"insert('// return true if student \"grade\" is not a \"D\" or \"F\"\nfunction isGoodGrade(student) {\n\n}\n')"
42
+
]
43
+
},
44
+
{
45
+
"description": "Set `var myBest` to your scores, excluding any grades that are \"D\" or \"F\".",
46
+
"tests": [
47
+
"1/01/04-filter"
48
+
],
49
+
"actions": [
50
+
"insert('// filter out \"D\"'s and \"F\"'s here\nvar myBest = myData.filter();\n\n')"
51
+
]
52
+
}
53
+
]
54
+
},
10
55
{
11
56
"title": "Sort",
12
57
"description": "Array -> sorted Array",
@@ -82,7 +127,7 @@
82
127
"description": "coming soon"
83
128
}
84
129
],
85
-
"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/01/filter') -->"
130
+
"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."
0 commit comments