|
86 | 86 | "description": "`compareScore` should return -1 if the first score is more than the second",
|
87 | 87 | "tests": [
|
88 | 88 | "1/02/02-sort"
|
| 89 | + ], |
| 90 | + "hints": [ |
| 91 | + "set the second case to `b.score < a.score`" |
89 | 92 | ]
|
90 | 93 | },
|
91 | 94 | {
|
92 | 95 | "description": "`compareScore` should return 0 if the first score is the same as the second",
|
93 | 96 | "tests": [
|
94 | 97 | "1/02/03-sort"
|
| 98 | + ], |
| 99 | + "hints": [ |
| 100 | + "no case is necessary, use the `default` case" |
95 | 101 | ]
|
96 | 102 | },
|
97 | 103 | {
|
|
101 | 107 | ],
|
102 | 108 | "actions": [
|
103 | 109 | "insert('// use the compare function to sort myBest\nvar mySorted = myBest\n')"
|
| 110 | + ], |
| 111 | + "hints": [ |
| 112 | + "try using `myBest.sort()`" |
104 | 113 | ]
|
105 | 114 | }
|
106 | 115 | ]
|
|
118 | 127 | "actions": [
|
119 | 128 | "open('03-map.js')",
|
120 | 129 | "set('// change any `student.grade`'s into an 'A'\nfunction changeGrade() {\n\n}\n')"
|
| 130 | + ], |
| 131 | + "hints": [ |
| 132 | + "give `changeGrade` a parameter, call it \"student\"", |
| 133 | + "match for `student.grade`", |
| 134 | + "match where `student.grade === 'A'`" |
121 | 135 | ]
|
122 | 136 | },
|
123 | 137 | {
|
|
136 | 150 | ],
|
137 | 151 | "actions": [
|
138 | 152 | "insert('\nfunction increaseScore() {\n\n}\n\n// map over `mySlightlyChanged` with a function `increaseScore` to increment each score by 12\nvar mySlightlyChanged = myData;\n')"
|
| 153 | + ], |
| 154 | + "hints": [ |
| 155 | + "give `increaseScore` a parameter, call it \"student\"", |
| 156 | + "it should increase `student.score`", |
| 157 | + "return `student`" |
139 | 158 | ]
|
140 | 159 | },
|
141 | 160 | {
|
142 |
| - "description": "Wait. Now you're getting 105 in \"Algorithm Design\" class. Fix `increaseScores` so that the maximum score is 95. That should be less suspicious.", |
| 161 | + "description": "Wait. Now you're getting 105 in \"Algorithm Design\" class. Fix `increaseScore` so that the maximum score is 95. That should be less suspicious.", |
143 | 162 | "tests": [
|
144 | 163 | "1/03/04-map"
|
| 164 | + ], |
| 165 | + "hints": [ |
| 166 | + "use an if clause within `increaseScore`", |
| 167 | + "try `if (student.score >= 95) { student.score = 95 }`" |
145 | 168 | ]
|
146 | 169 | },
|
147 | 170 | {
|
|
151 | 174 | ],
|
152 | 175 | "actions": [
|
153 | 176 | "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')"
|
| 177 | + ], |
| 178 | + "hints": [ |
| 179 | + "change `getGrade` to take a `student` param instead of `score`", |
| 180 | + "change the grade and return the `student`", |
| 181 | + "set `student.grade = \"A\"` and return `student`" |
154 | 182 | ]
|
155 | 183 | },
|
156 | 184 | {
|
|
160 | 188 | ],
|
161 | 189 | "actions": [
|
162 | 190 | "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')"
|
| 191 | + ], |
| 192 | + "hints": [ |
| 193 | + "use `map` to return only the \"score\" & \"grade\" fields", |
| 194 | + "map with a function with a parameter, call it \"student\"", |
| 195 | + "return `{ score: student.score, grade: student.grade }`" |
163 | 196 | ]
|
164 | 197 | }
|
165 | 198 | ]
|
|
177 | 210 | "actions": [
|
178 | 211 | "open('04-forEach.js')",
|
179 | 212 | "set('function logCourse(course) {\n console.log(`${course.grade} ${course.score} ${course.title}`);\n}\n\n// log your grades to the console\nmyFixed.forEach();\n')"
|
| 213 | + ], |
| 214 | + "hints": [ |
| 215 | + "call `forEach` with `logCourse`" |
180 | 216 | ]
|
181 | 217 | },
|
182 | 218 | {
|
|
186 | 222 | ],
|
187 | 223 | "actions": [
|
188 | 224 | "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')"
|
| 225 | + ], |
| 226 | + "hints": [ |
| 227 | + "Array methods can take more than one parameter", |
| 228 | + "Add a second parameter to `logCourseWithIndex`" |
189 | 229 | ]
|
190 | 230 | },
|
191 | 231 | {
|
|
195 | 235 | ],
|
196 | 236 | "actions": [
|
197 | 237 | "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')"
|
| 238 | + ], |
| 239 | + "hints": [ |
| 240 | + "Array methods can take more than one parameter", |
| 241 | + "Add a third parameter to `logCourseWithIndexAndArray`" |
198 | 242 | ]
|
199 | 243 | },
|
200 | 244 | {
|
|
220 | 264 | ],
|
221 | 265 | "actions": [
|
222 | 266 | "open('05-find.js')",
|
223 |
| - "set('// filter for students.title is \"Web Security\"\nvar myClass = students.filter();\n')" |
| 267 | + "set('// filter for the student title matches \"Web Security\"\nvar myClass = students.filter();\n')" |
| 268 | + ], |
| 269 | + "hints": [ |
| 270 | + "create a `filter` function", |
| 271 | + "filter for `student.title === \"Web Security\"`" |
224 | 272 | ]
|
225 | 273 | },
|
226 | 274 | {
|
|
229 | 277 | "1/05/02-find"
|
230 | 278 | ],
|
231 | 279 | "actions": [
|
232 |
| - "insert('\n// search for a student with a name\n// not matching students in the list\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')", |
233 |
| - "insert('// hint: use `indexOf` to find if an item is in the array\nfunction notInList() {\n\n}\n\n// find using `notInList`\nvar unknownStudent = myClass.find();\n')" |
| 280 | + "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')", |
| 281 | + "insert('// search for a student with a name\n// not matching students in `otherStudents`\nfunction notInList() {\n\n}\n\n// find using `notInList`\nvar unknownStudent = myClass.find();\n')" |
| 282 | + ], |
| 283 | + "hints": [ |
| 284 | + "use `indexOf` to find what doesn't match", |
| 285 | + "use `otherStudents.indexOf(x) === -1` to find what doesn't match", |
| 286 | + "match for `student.name`" |
234 | 287 | ]
|
235 | 288 | },
|
236 | 289 | {
|
|
240 | 293 | ],
|
241 | 294 | "actions": [
|
242 | 295 | "insert('\n// filter using `notInList`\nvar unknownStudentList = students.filter();\n')"
|
| 296 | + ], |
| 297 | + "hints": [ |
| 298 | + "consider reusing a function" |
243 | 299 | ]
|
244 | 300 | },
|
245 | 301 | {
|
|
248 | 304 | "1/05/04-find"
|
249 | 305 | ],
|
250 | 306 | "actions": [
|
251 |
| - "insert('\n// use `map` to return only the `student.name`\nvar unknownStudentNames = unknownStudentList.map();\n')" |
| 307 | + "insert('\n// list only student names\nvar unknownStudentNames = unknownStudentList.map();\n')" |
| 308 | + ], |
| 309 | + "hints": [ |
| 310 | + "use `map` to return only the `student.name`" |
252 | 311 | ]
|
253 | 312 | },
|
254 | 313 | {
|
|
258 | 317 | ],
|
259 | 318 | "actions": [
|
260 | 319 | "insert('\n// use `.join('')` to join the array of strings\nvar decodedName = unknownStudentNames;\nconsole.log(decodedName);\n')"
|
| 320 | + ], |
| 321 | + "hints": [ |
| 322 | + "call `join` following `unknownStudentNames`" |
261 | 323 | ]
|
262 | 324 | },
|
263 | 325 | {
|
|
282 | 344 | "open('06-concat.js')",
|
283 | 345 | "set('// Array.prototype can be used to create new Array methods\nArray.prototype.flatten = function() {\n return this.reduce(function(a, b) {\n return a.concat(b);\n }, []);\n};\n')",
|
284 | 346 | "insert('\nvar numberedList = [[1, 2], [3, 4]];\n\n// use `flatten` on `numberedList`\nvar flattenedArray = numberedList;\n')"
|
| 347 | + ], |
| 348 | + "hints": [ |
| 349 | + "call `.flatten()` on `numberedList`" |
285 | 350 | ]
|
286 | 351 | },
|
287 | 352 | {
|
|
291 | 356 | ],
|
292 | 357 | "actions": [
|
293 | 358 | "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')"
|
| 359 | + ], |
| 360 | + "hints": [ |
| 361 | + "pair `course.title`", |
| 362 | + "pair `student.name`" |
294 | 363 | ]
|
295 | 364 | },
|
296 | 365 | {
|
|
300 | 369 | ],
|
301 | 370 | "actions": [
|
302 | 371 | "insert('// `flatten` doubleArray\nvar students = doubleArray;\n')"
|
| 372 | + ], |
| 373 | + "hints": [ |
| 374 | + "call `.flatten()` on `doubleArray`" |
303 | 375 | ]
|
304 | 376 | },
|
305 | 377 | {
|
|
315 | 387 | "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.",
|
316 | 388 | "tests": [
|
317 | 389 | "1/06/05-concat"
|
| 390 | + ], |
| 391 | + "hints": [ |
| 392 | + "call `suspects.concat()` with `newSuspects`" |
318 | 393 | ]
|
319 | 394 | }
|
320 | 395 | ]
|
|
331 | 406 | ],
|
332 | 407 | "actions": [
|
333 | 408 | "open('07-reduce.js')",
|
334 |
| - "set('var practice = [1, 1, 2, 3, 5, 8, 13, 21];\n\nfunction add(a, b) {\n return a + b;\n}\n\n// total the numbers using a reduce function\n// initialValue defaults to 0\nvar total = practice.reduce();\n')" |
| 409 | + "set('var practice = [1, 1, 2, 3, 5, 8, 13, 21];\n\nfunction add(a, b) {\n return a + b;\n}\n\n// total the numbers using a reduce function\nvar total = practice.reduce();\n')" |
| 410 | + ], |
| 411 | + "hints": [ |
| 412 | + "with only numbers, the initialValue defaults to 0", |
| 413 | + "just call `reduce` with `add`" |
335 | 414 | ]
|
336 | 415 | },
|
337 | 416 | {
|
|
340 | 419 | "1/07/02-reduce"
|
341 | 420 | ],
|
342 | 421 | "actions": [
|
343 |
| - "insert('\nvar averages = courses.map(function(course) {\n var sum = course.students.reduce(function(total, student) {\n // calculate score totals here\n\n // set initialValue to 0\n });\n return Math.round(sum / course.students.length, 0);\n});\n')" |
| 422 | + "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')" |
| 423 | + ], |
| 424 | + "hints": [ |
| 425 | + "set the initialValue to 0", |
| 426 | + "like this: `reduce(function () {}, 0)`", |
| 427 | + "return the sum of `student.score` and `total`" |
344 | 428 | ]
|
345 | 429 | },
|
346 | 430 | {
|
|
349 | 433 | "1/07/03-reduce"
|
350 | 434 | ],
|
351 | 435 | "actions": [
|
352 |
| - "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 // add a new {name: '', scores: [72]} object\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')" |
| 436 | + "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')" |
| 437 | + ], |
| 438 | + "hints": [ |
| 439 | + "if the name is new, push an object with name & scores: `{ name: '', scores: [42]}`", |
| 440 | + "match for `next.name` & `next.score`", |
| 441 | + "you can concat the scores onto an array: `[].concat(next.score)`", |
| 442 | + "if the name is already in the list, just add the `next.score`" |
353 | 443 | ]
|
354 | 444 | },
|
355 | 445 | {
|
|
358 | 448 | "1/07/04-reduce"
|
359 | 449 | ],
|
360 | 450 | "actions": [
|
361 |
| - "insert('\nvar suspectStats = suspectScores.map(function(suspect) {\n // calculate the total difference in scores from the averages\n // you may want to third reduce param: index\n var difference = suspect.scores.reduce();\n\n return {\n name: suspect.name,\n scores: suspect.scores,\n difference: difference\n };\n});\n')" |
| 451 | + "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')" |
| 452 | + ], |
| 453 | + "hints": [ |
| 454 | + "You may want to use a second param: `index`", |
| 455 | + "Compare the `suspect.scores[index]` with the `averages[index]`", |
| 456 | + "To get a sum, start your `reduce` function at 0" |
362 | 457 | ]
|
363 | 458 | },
|
364 | 459 | {
|
|
367 | 462 | "1/07/05-reduce"
|
368 | 463 | ],
|
369 | 464 | "actions": [
|
370 |
| - "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() {}, []).join(', ');\n')" |
| 465 | + "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')" |
| 466 | + ], |
| 467 | + "hints": [ |
| 468 | + "use `.join(', ')`" |
371 | 469 | ]
|
372 | 470 | },
|
373 | 471 | {
|
|
0 commit comments