|
11 | 11 | { |
12 | 12 | "description": "Set `first` to the first item in the `students` array.", |
13 | 13 | "tests": [ |
14 | | - "1/00/01-setup" |
| 14 | + "00/01-setup" |
15 | 15 | ], |
16 | 16 | "actions": [ |
17 | 17 | "open('00-setup.js')", |
|
25 | 25 | { |
26 | 26 | "description": "Set `myName` to the \"name\" of the first student in the list.", |
27 | 27 | "tests": [ |
28 | | - "1/00/02-setup" |
| 28 | + "00/02-setup" |
29 | 29 | ], |
30 | 30 | "actions": [ |
31 | 31 | "insert('var myName= ::>\n')" |
|
39 | 39 | { |
40 | 40 | "description": "Log your name to the console.", |
41 | 41 | "tests": [ |
42 | | - "1/00/03-setup" |
| 42 | + "00/03-setup" |
43 | 43 | ], |
44 | 44 | "actions": [ |
45 | 45 | "insert('\nconsole.log(::>);\n')" |
|
59 | 59 | { |
60 | 60 | "description": "Write a filter condition function called `isAda` that returns true only if the name matches your name: \"Ada Lovelace\".", |
61 | 61 | "tests": [ |
62 | | - "1/01/01-filter" |
| 62 | + "01/01-filter" |
63 | 63 | ], |
64 | 64 | "actions": [ |
65 | 65 | "open('01-filter.js')", |
|
74 | 74 | { |
75 | 75 | "description": "Set `var myData` to filter with the `isAda` function.", |
76 | 76 | "tests": [ |
77 | | - "1/01/02-filter" |
| 77 | + "01/02-filter" |
78 | 78 | ], |
79 | 79 | "actions": [ |
80 | 80 | "insert('// run the function name in filter\nvar myData = students.filter(::>);\n')" |
|
87 | 87 | { |
88 | 88 | "description": "Write a filter condition called `isGoodGrade` that will filter out any \"D\" or \"F\" grades.", |
89 | 89 | "tests": [ |
90 | | - "1/01/03-filter" |
| 90 | + "01/03-filter" |
91 | 91 | ], |
92 | 92 | "actions": [ |
93 | 93 | "insert('\n\n// return true if student.grade is not a \"D\" or \"F\"\nfunction isGoodGrade(student) {\n ::>\n}\n')" |
|
117 | 117 | { |
118 | 118 | "description": "`compareScore` should return 1 if the first score is less than the second", |
119 | 119 | "tests": [ |
120 | | - "1/02/01-sort" |
| 120 | + "02/01-sort" |
121 | 121 | ], |
122 | 122 | "actions": [ |
123 | 123 | "open('02-sort.js')", |
|
127 | 127 | { |
128 | 128 | "description": "`compareScore` should return -1 if the first score is more than the second", |
129 | 129 | "tests": [ |
130 | | - "1/02/02-sort" |
| 130 | + "02/02-sort" |
131 | 131 | ], |
132 | 132 | "hints": [ |
133 | 133 | "set the second case to `b.score < a.score`" |
|
136 | 136 | { |
137 | 137 | "description": "`compareScore` should return 0 if the first score is the same as the second", |
138 | 138 | "tests": [ |
139 | | - "1/02/03-sort" |
| 139 | + "02/03-sort" |
140 | 140 | ], |
141 | 141 | "hints": [ |
142 | 142 | "no case is necessary, use the `default` case" |
|
145 | 145 | { |
146 | 146 | "description": "Set `mySorted` to the result of `myBest` sorted by `compareScore`", |
147 | 147 | "tests": [ |
148 | | - "1/02/04-sort" |
| 148 | + "02/04-sort" |
149 | 149 | ], |
150 | 150 | "actions": [ |
151 | 151 | "insert('// use the compare function to sort myBest\nvar mySorted = myBest::>\n')" |
|
164 | 164 | { |
165 | 165 | "description": "Make a function `changeGrade` that takes student data and changes all grades to \"A\"s.", |
166 | 166 | "tests": [ |
167 | | - "1/03/01-map" |
| 167 | + "03/01-map" |
168 | 168 | ], |
169 | 169 | "actions": [ |
170 | 170 | "open('03-map.js')", |
|
179 | 179 | { |
180 | 180 | "description": "Map over the `myData` with the `changeGrade` function. Set `myChanged` to the result.", |
181 | 181 | "tests": [ |
182 | | - "1/03/02-map" |
| 182 | + "03/02-map" |
183 | 183 | ], |
184 | 184 | "actions": [ |
185 | 185 | "insert('// map over `myData` with the `changeGrade` function\nvar myChanged = myData.map(::>);\n')" |
|
188 | 188 | { |
189 | 189 | "description": "Hold up. An A in \"Data Science\" class looks way to suspicious. Your parents might catch on to your cheating.\n\nLet's go back to `myData` and instead increment each score by 12 points.", |
190 | 190 | "tests": [ |
191 | | - "1/03/03-map" |
| 191 | + "03/03-map" |
192 | 192 | ], |
193 | 193 | "actions": [ |
194 | 194 | "insert('\nfunction increaseScore(::>) {\n\n}\n\n// map over `mySlightlyChanged` with a function `increaseScore` to increment each score by 12\nvar mySlightlyChanged = myData;\n')" |
|
212 | 212 | { |
213 | 213 | "description": "One more problem. Now the scores don't match the grades. you have 95 score in \"3D Computer Graphics\", but only a \"B\" grade. Set `myFixed` as the result of using the `getGrade` function to set grades according to their new scores.", |
214 | 214 | "tests": [ |
215 | | - "1/03/05-map" |
| 215 | + "03/05-map" |
216 | 216 | ], |
217 | 217 | "actions": [ |
218 | 218 | "insert('\n// change `getGrade` to accept an object\n// and return an object\nfunction getGrade(score) {\n switch (true) {\n case (score >= 90):\n return \"A\";\n case (score >= 80):\n return \"B\";\n case (score >= 70):\n return \"C\";\n case (score >= 60):\n return \"D\";\n default:\n return \"F\";\n }\n}\n\n// map `myFixed` to update grades to the new scores\nvar myFixed = mySlightlyChanged;\n')" |
|
226 | 226 | { |
227 | 227 | "description": "Check to make sure everything is working. Set `scoresAndGrades` to an array of scores and grades only.", |
228 | 228 | "tests": [ |
229 | | - "1/03/06-map" |
| 229 | + "03/06-map" |
230 | 230 | ], |
231 | 231 | "actions": [ |
232 | 232 | "insert('\n// set `scoresAndGrades` to an array of scores and grades\n// it should return an array of objects like this: {score: 75, grade: 'C'}\nvar scoresAndGrades = myFixed::>\n')" |
|
247 | 247 | { |
248 | 248 | "description": "Use `forEach` to log out your report card to the console", |
249 | 249 | "tests": [ |
250 | | - "1/04/01-forEach" |
| 250 | + "04/01-forEach" |
251 | 251 | ], |
252 | 252 | "actions": [ |
253 | 253 | "open('04-forEach.js')", |
|
260 | 260 | { |
261 | 261 | "description": "Add a second parameter to `logCourseWithIndex` called `index`. Then call the function with `myFixed.forEach`.", |
262 | 262 | "tests": [ |
263 | | - "1/04/02-forEach" |
| 263 | + "04/02-forEach" |
264 | 264 | ], |
265 | 265 | "actions": [ |
266 | 266 | "insert('\n// add a second param called 'index' to the function\nfunction logCourseWithIndex(course::>) {\n console.log(`${index + 1} ${course.grade} ${course.score} ${course.title}`);\n}\n\n// log your grades to the console with an index\nmyFixed.forEach(logCourseWithIndex);\n')" |
|
273 | 273 | { |
274 | 274 | "description": "Add a third parameter called `array` to `logCourseWithIndexAndArray`, then call the function with `myFixed.forEach`.", |
275 | 275 | "tests": [ |
276 | | - "1/04/03-forEach" |
| 276 | + "04/03-forEach" |
277 | 277 | ], |
278 | 278 | "actions": [ |
279 | 279 | "insert('\n// add a third param called 'array' to the function\nfunction logCourseWithIndexAndArray(course, index::>) {\n console.log(`${index + 1}/${array.length} ${course.grade} ${course.score} ${course.title}`);\n}\n\n// log your grades to the console with an index and array length\nmyFixed.forEach(logCourseWithIndexAndArray);\n')" |
|
286 | 286 | { |
287 | 287 | "description": "What??? Suddenly Your data has all disappeared!\n\nIt seems `myFixed` relies on a chain of methods.\n\n```js\nmyFixed = students\n .filter(isAda)\n .sort(compareScore)\n .map(increaseScore)\n .map(getGrade)\n .forEach(logCourseWithIndexAndArray)\n```\n\nThis is why side-effects are dangerous. Students data must have changed, and now all of your transformations are effected.", |
288 | 288 | "tests": [ |
289 | | - "1/04/04-forEach" |
| 289 | + "04/04-forEach" |
290 | 290 | ], |
291 | 291 | "actions": [ |
292 | 292 | "insert('\nconsole.log(myFixed);\n')" |
|
302 | 302 | { |
303 | 303 | "description": "`filter` to `students` in the class titled \"Web Security\"", |
304 | 304 | "tests": [ |
305 | | - "1/05/01-find" |
| 305 | + "05/01-find" |
306 | 306 | ], |
307 | 307 | "actions": [ |
308 | 308 | "open('05-find.js')", |
|
316 | 316 | { |
317 | 317 | "description": "`find` the name in `myClass` that isn't in the list of known students", |
318 | 318 | "tests": [ |
319 | | - "1/05/02-find" |
| 319 | + "05/02-find" |
320 | 320 | ], |
321 | 321 | "actions": [ |
322 | 322 | "insert('\nvar otherStudents = [\"Albert Gonzalez\", \"Brian Kernaghan\", \"Danielle Bunten Berry\", \"Donald Knuth\", \"Grace Hopper\", \"Hack Kerr\", \"James Gosling\", \"Ken Thompson\", \"Kevin Mitnick\", \"Linus Torvalds\", \"Niklaus Wirth\", \"Rebecca Heineman\", \"Tim Berners-Lee\", \"Xiao Tian\", \"Ying Cracker\"];\n\n')", |
|
331 | 331 | { |
332 | 332 | "description": "`filter` down to students without known names", |
333 | 333 | "tests": [ |
334 | | - "1/05/03-find" |
| 334 | + "05/03-find" |
335 | 335 | ], |
336 | 336 | "actions": [ |
337 | 337 | "insert('\n// filter using `notInList`\nvar unknownStudentList = students.filter(::>);\n')" |
|
343 | 343 | { |
344 | 344 | "description": "`map` over the result to get only the `name` property", |
345 | 345 | "tests": [ |
346 | | - "1/05/04-find" |
| 346 | + "05/04-find" |
347 | 347 | ], |
348 | 348 | "actions": [ |
349 | 349 | "insert('\n// list only student names\nvar unknownStudentNames = unknownStudentList.map(::>);\n')" |
|
355 | 355 | { |
356 | 356 | "description": "`join('')` the array of names to output the result as a string", |
357 | 357 | "tests": [ |
358 | | - "1/05/05-find" |
| 358 | + "05/05-find" |
359 | 359 | ], |
360 | 360 | "actions": [ |
361 | 361 | "insert('\n// use `.join('')` to join the array of strings\nvar decodedName = unknownStudentNames::>;\nconsole.log(decodedName);\n')" |
|
374 | 374 | { |
375 | 375 | "description": "First, test out `flatten` on the `flattenedArray`", |
376 | 376 | "tests": [ |
377 | | - "1/06/01-concat" |
| 377 | + "06/01-concat" |
378 | 378 | ], |
379 | 379 | "actions": [ |
380 | 380 | "open('06-concat.js')", |
|
388 | 388 | { |
389 | 389 | "description": "Now `map` over the courses array, and `map` over the students array inside of it.\nReturn the fields:\n\n * title\n * instructor\n * name\n * grade\n * score", |
390 | 390 | "tests": [ |
391 | | - "1/06/02-concat" |
| 391 | + "06/02-concat" |
392 | 392 | ], |
393 | 393 | "actions": [ |
394 | 394 | "insert('\n// map over courses then\n// map over students inside of courses\nvar doubleArray = courses.map(function(course) {\n return course.students.map(function(student) {\n return {\n // fill in the fields\n title: ::>'',\n instructor: '',\n name: '',\n score: '',\n grade: ''\n };\n });\n});\n\n')" |
|
401 | 401 | { |
402 | 402 | "description": "Use `flatten` to put all data into a single array. Set `students` to the result.", |
403 | 403 | "tests": [ |
404 | | - "1/06/03-concat" |
| 404 | + "06/03-concat" |
405 | 405 | ], |
406 | 406 | "actions": [ |
407 | 407 | "insert('// `flatten` doubleArray\nvar students = doubleArray::>;\n')" |
|
413 | 413 | { |
414 | 414 | "description": "Use the `suspects` array to `filter` to only \"Hack Kerr\"'s data", |
415 | 415 | "tests": [ |
416 | | - "1/06/04-concat" |
| 416 | + "06/04-concat" |
417 | 417 | ], |
418 | 418 | "actions": [ |
419 | 419 | "insert('\nvar suspects = [\"Hack Kerr\"];\n// filter to data matching `suspects`\n\nvar suspectData = students::>;\n')" |
|
422 | 422 | { |
423 | 423 | "description": "You just thought of two more suspects! Make a new variable called `newSuspects` and add it above `suspects`.\n\n```js\nvar newSuspects = ['Albert Gonzalez', 'Kevin Mitnick'];\n```\n\n`concat` the `newSuspects` onto the `suspects` list.", |
424 | 424 | "tests": [ |
425 | | - "1/06/05-concat" |
| 425 | + "06/05-concat" |
426 | 426 | ], |
427 | 427 | "hints": [ |
428 | 428 | "call `suspects.concat()` with `newSuspects`" |
|
438 | 438 | { |
439 | 439 | "description": "Use `reduce` to sum the numbers in the `practice` array", |
440 | 440 | "tests": [ |
441 | | - "1/07/01-reduce" |
| 441 | + "07/01-reduce" |
442 | 442 | ], |
443 | 443 | "actions": [ |
444 | 444 | "open('07-reduce.js')", |
|
452 | 452 | { |
453 | 453 | "description": "Not all reduce functions are so easy. `reduce` is a little more difficult to master.\n\n`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.", |
454 | 454 | "tests": [ |
455 | | - "1/07/02-reduce" |
| 455 | + "07/02-reduce" |
456 | 456 | ], |
457 | 457 | "actions": [ |
458 | 458 | "insert('\nvar averages = courses.map(function(course) {\n var sum = course.students.reduce(function(total, student) {\n ::>\n\n });\n return Math.round(sum / course.students.length, 0);\n});\n')" |
|
466 | 466 | { |
467 | 467 | "description": "`reduce` to an array of suspect scores from the `suspectData` we collected previously.", |
468 | 468 | "tests": [ |
469 | | - "1/07/03-reduce" |
| 469 | + "07/03-reduce" |
470 | 470 | ], |
471 | 471 | "actions": [ |
472 | 472 | "insert('\n// [{ name: 'suspectName', scores: [ 50, 65, 75, 85...] } ...]\nvar suspectScores = suspectData.reduce(function(total, next) {\n // see if suspect name has a list yet\n var index = total.findIndex(function(suspect) {\n return suspect.name === next.name;\n });\n if (index < 0) {\n total.push({\n ::>\n\n });\n } else {\n // push the next score onto the suspects scores\n total[index].scores.push();\n }\n return total;\n}, []);\n\n')" |
|
481 | 481 | { |
482 | 482 | "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 ...],\n difference: 15\n}]\n```", |
483 | 483 | "tests": [ |
484 | | - "1/07/04-reduce" |
| 484 | + "07/04-reduce" |
485 | 485 | ], |
486 | 486 | "actions": [ |
487 | 487 | "insert('\nvar suspectStats = suspectScores.map(function(suspect) {\n // calculate the total difference in scores from the averages\n var difference = suspect.scores.reduce(::>);\n\n return {\n name: suspect.name,\n scores: suspect.scores,\n difference: difference\n };\n});\n')" |
|
495 | 495 | { |
496 | 496 | "description": "`reduce` down to likely suspect names by filtering with the `isCheater` function.\n\nThis could be done with a `filter` & `map`, but it is simpler to just use one `reduce`.", |
497 | 497 | "tests": [ |
498 | | - "1/07/05-reduce" |
| 498 | + "07/05-reduce" |
499 | 499 | ], |
500 | 500 | "actions": [ |
501 | 501 | "insert('\nfunction isCheater(suspect) {\n return suspect.difference > 200;\n}\n\n// reduce down to a string of likely suspects\nvar likelySuspects = suspectStats.reduce(function(::>) {}, []);\n')" |
|
507 | 507 | { |
508 | 508 | "description": "It looks like we have a likely suspect.", |
509 | 509 | "tests": [ |
510 | | - "1/07/06-reduce" |
| 510 | + "07/06-reduce" |
511 | 511 | ], |
512 | 512 | "actions": [ |
513 | 513 | "insert('console.log(likelySuspects);\n')" |
|
0 commit comments