Skip to content

Commit a27086a

Browse files
committedFeb 27, 2016
add more hints
·
v0.2.20.1.7
1 parent 0d78eb4 commit a27086a

File tree

8 files changed

+166
-23
lines changed

8 files changed

+166
-23
lines changed
 

‎coderoad.json‎

Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@
8686
"description": "`compareScore` should return -1 if the first score is more than the second",
8787
"tests": [
8888
"1/02/02-sort"
89+
],
90+
"hints": [
91+
"set the second case to `b.score < a.score`"
8992
]
9093
},
9194
{
9295
"description": "`compareScore` should return 0 if the first score is the same as the second",
9396
"tests": [
9497
"1/02/03-sort"
98+
],
99+
"hints": [
100+
"no case is necessary, use the `default` case"
95101
]
96102
},
97103
{
@@ -101,6 +107,9 @@
101107
],
102108
"actions": [
103109
"insert('// use the compare function to sort myBest\nvar mySorted = myBest\n')"
110+
],
111+
"hints": [
112+
"try using `myBest.sort()`"
104113
]
105114
}
106115
]
@@ -118,6 +127,11 @@
118127
"actions": [
119128
"open('03-map.js')",
120129
"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'`"
121135
]
122136
},
123137
{
@@ -136,12 +150,21 @@
136150
],
137151
"actions": [
138152
"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`"
139158
]
140159
},
141160
{
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.",
143162
"tests": [
144163
"1/03/04-map"
164+
],
165+
"hints": [
166+
"use an if clause within `increaseScore`",
167+
"try `if (student.score >= 95) { student.score = 95 }`"
145168
]
146169
},
147170
{
@@ -151,6 +174,11 @@
151174
],
152175
"actions": [
153176
"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`"
154182
]
155183
},
156184
{
@@ -160,6 +188,11 @@
160188
],
161189
"actions": [
162190
"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 }`"
163196
]
164197
}
165198
]
@@ -177,6 +210,9 @@
177210
"actions": [
178211
"open('04-forEach.js')",
179212
"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`"
180216
]
181217
},
182218
{
@@ -186,6 +222,10 @@
186222
],
187223
"actions": [
188224
"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`"
189229
]
190230
},
191231
{
@@ -195,6 +235,10 @@
195235
],
196236
"actions": [
197237
"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`"
198242
]
199243
},
200244
{
@@ -220,7 +264,11 @@
220264
],
221265
"actions": [
222266
"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\"`"
224272
]
225273
},
226274
{
@@ -229,8 +277,13 @@
229277
"1/05/02-find"
230278
],
231279
"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`"
234287
]
235288
},
236289
{
@@ -240,6 +293,9 @@
240293
],
241294
"actions": [
242295
"insert('\n// filter using `notInList`\nvar unknownStudentList = students.filter();\n')"
296+
],
297+
"hints": [
298+
"consider reusing a function"
243299
]
244300
},
245301
{
@@ -248,7 +304,10 @@
248304
"1/05/04-find"
249305
],
250306
"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`"
252311
]
253312
},
254313
{
@@ -258,6 +317,9 @@
258317
],
259318
"actions": [
260319
"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`"
261323
]
262324
},
263325
{
@@ -282,6 +344,9 @@
282344
"open('06-concat.js')",
283345
"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')",
284346
"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`"
285350
]
286351
},
287352
{
@@ -291,6 +356,10 @@
291356
],
292357
"actions": [
293358
"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`"
294363
]
295364
},
296365
{
@@ -300,6 +369,9 @@
300369
],
301370
"actions": [
302371
"insert('// `flatten` doubleArray\nvar students = doubleArray;\n')"
372+
],
373+
"hints": [
374+
"call `.flatten()` on `doubleArray`"
303375
]
304376
},
305377
{
@@ -315,6 +387,9 @@
315387
"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.",
316388
"tests": [
317389
"1/06/05-concat"
390+
],
391+
"hints": [
392+
"call `suspects.concat()` with `newSuspects`"
318393
]
319394
}
320395
]
@@ -331,7 +406,11 @@
331406
],
332407
"actions": [
333408
"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`"
335414
]
336415
},
337416
{
@@ -340,7 +419,12 @@
340419
"1/07/02-reduce"
341420
],
342421
"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`"
344428
]
345429
},
346430
{
@@ -349,7 +433,13 @@
349433
"1/07/03-reduce"
350434
],
351435
"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`"
353443
]
354444
},
355445
{
@@ -358,7 +448,12 @@
358448
"1/07/04-reduce"
359449
],
360450
"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"
362457
]
363458
},
364459
{
@@ -367,7 +462,10 @@
367462
"1/07/05-reduce"
368463
],
369464
"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(', ')`"
371469
]
372470
},
373471
{

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-functional-school",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Coderoad tutorial",
55
"author": "Shawn McKay <shawn.j.mckay@gmail.com> (http://shmck.com)",
66
"contributers": [],

‎tutorial/1/02/sort.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ function compareScore(a, b) {
5454
))
5555
+ `compareScore` should return -1 if the first score is more than the second
5656
@test('1/02/02-sort')
57+
@hint('set the second case to `b.score < a.score`')
5758

5859
+ `compareScore` should return 0 if the first score is the same as the second
5960
@test('1/02/03-sort')
61+
@hint('no case is necessary, use the `default` case')
6062

6163
+ Set `mySorted` to the result of `myBest` sorted by `compareScore`
6264
@test('1/02/04-sort')
@@ -66,3 +68,4 @@ function compareScore(a, b) {
6668
var mySorted = myBest
6769
```
6870
))
71+
@hint('try using `myBest.sort()`')

‎tutorial/1/03/map.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ function changeGrade() {
6767
}
6868
```
6969
))
70+
@hint('give `changeGrade` a parameter, call it "student"')
71+
@hint('match for `student.grade`')
72+
@hint('match where `student.grade === 'A'`')
7073

7174

7275
+ Map over the `myData` with the `changeGrades` function. Set `myChanged` to the result.
@@ -78,6 +81,7 @@ var myChanged = myData.map();
7881
```
7982
))
8083

84+
8185
+ Hold up. An A in "Data Science" class looks way to suspicious. Your parents might catch on to your cheating.
8286

8387
Let's go back to `myData` and instead increment each score by 12 points.
@@ -93,9 +97,14 @@ function increaseScore() {
9397
var mySlightlyChanged = myData;
9498
```
9599
))
100+
@hint('give `increaseScore` a parameter, call it "student"')
101+
@hint('it should increase `student.score`')
102+
@hint('return `student`')
96103

97-
+ Wait. Now you're getting 105 in "Algorithm Design" class. Fix `increaseScores` so that the maximum score is 95. That should be less suspicious.
104+
+ Wait. Now you're getting 105 in "Algorithm Design" class. Fix `increaseScore` so that the maximum score is 95. That should be less suspicious.
98105
@test('1/03/04-map')
106+
@hint('use an if clause within `increaseScore`')
107+
@hint('try `if (student.score >= 95) { student.score = 95 }`')
99108

100109
+ 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.
101110
@test('1/03/05-map')
@@ -123,6 +132,9 @@ function getGrade(score) {
123132
var myFixed = mySlightlyChanged;
124133
```
125134
))
135+
@hint('change `getGrade` to take a `student` param instead of `score`')
136+
@hint('change the grade and return the `student`')
137+
@hint('set `student.grade = "A"` and return `student`')
126138

127139
+ Check to make sure everything is working. Set `scoresAndGrades` to an array of scores and grades only.
128140
@test('1/03/06-map')
@@ -134,3 +146,6 @@ var myFixed = mySlightlyChanged;
134146
var scoresAndGrades = myFixed;
135147
```
136148
))
149+
@hint('use `map` to return only the "score" & "grade" fields')
150+
@hint('map with a function with a parameter, call it "student"')
151+
@hint('return `{ score: student.score, grade: student.grade }`')

‎tutorial/1/04/forEach.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function logCourse(course) {
9999
myFixed.forEach();
100100
```
101101
))
102+
@hint('call `forEach` with `logCourse`')
102103

103104
+ Add a second parameter to `logCourseWithIndex` called `index`. Then call the function with `myFixed.forEach`.
104105
@test('1/04/02-forEach')
@@ -114,6 +115,8 @@ function logCourseWithIndex(course) {
114115
myFixed.forEach(logCourseWithIndex);
115116
```
116117
))
118+
@hint('Array methods can take more than one parameter')
119+
@hint('Add a second parameter to `logCourseWithIndex`')
117120

118121
+ Add a third parameter called `array` to `logCourseWithIndexAndArray`, then call the function with `myFixed.forEach`.
119122
@test('1/04/03-forEach')
@@ -129,6 +132,8 @@ function logCourseWithIndexAndArray(course, index) {
129132
myFixed.forEach(logCourseWithIndexAndArray);
130133
```
131134
))
135+
@hint('Array methods can take more than one parameter')
136+
@hint('Add a third parameter to `logCourseWithIndexAndArray`')
132137

133138
+ What??? Suddenly Your data has all disappeared!
134139

‎tutorial/1/05/find.md‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,26 @@ Find is great for performantly matching unique values in data, such as an "id",
3030
@action(open('05-find.js'))
3131
@action(set(
3232
```
33-
// filter for students.title is "Web Security"
33+
// filter for the student title matches "Web Security"
3434
var myClass = students.filter();
3535
```
3636
))
37+
@hint('create a `filter` function')
38+
@hint('filter for `student.title === "Web Security"`')
3739

3840
+ `find` the name in `myClass` that isn't in the list of known students
3941
@test('1/05/02-find')
4042
@action(insert(
4143
```
4244
43-
// search for a student with a name
44-
// not matching students in the list
4545
var 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"];
4646
4747
```
4848
))
4949
@action(insert(
5050
```
51-
// hint: use `indexOf` to find if an item is in the array
51+
// search for a student with a name
52+
// not matching students in `otherStudents`
5253
function notInList() {
5354
5455
}
@@ -57,6 +58,9 @@ function notInList() {
5758
var unknownStudent = myClass.find();
5859
```
5960
))
61+
@hint('use `indexOf` to find what doesn't match')
62+
@hint('use `otherStudents.indexOf(x) === -1` to find what doesn't match')
63+
@hint('match for `student.name`')
6064

6165
+ `filter` down to students without known names
6266
@test('1/05/03-find')
@@ -67,16 +71,18 @@ var unknownStudent = myClass.find();
6771
var unknownStudentList = students.filter();
6872
```
6973
))
74+
@hint('consider reusing a function')
7075

7176
+ `map` over the result to get only the `name` property
7277
@test('1/05/04-find')
7378
@action(insert(
7479
```
7580
76-
// use `map` to return only the `student.name`
81+
// list only student names
7782
var unknownStudentNames = unknownStudentList.map();
7883
```
7984
))
85+
@hint('use `map` to return only the `student.name`')
8086

8187
+ `join('')` the array of names to output the result as a string
8288
@test('1/05/05-find')
@@ -88,6 +94,7 @@ var decodedName = unknownStudentNames;
8894
console.log(decodedName);
8995
```
9096
))
97+
@hint('call `join` following `unknownStudentNames`')
9198

9299
+ Very strange. In the next step, let's find out who wants revenge, and give it to him!
93100
@test('1/05/06-find')

‎tutorial/1/06/concat.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ var numberedList = [[1, 2], [3, 4]];
117117
var flattenedArray = numberedList;
118118
```
119119
))
120+
@hint('call `.flatten()` on `numberedList`')
120121

121122

122123
+ Now `map` over the courses array, and `map` over the students array inside of it.
@@ -148,6 +149,8 @@ var doubleArray = courses.map(function(course) {
148149
149150
```
150151
))
152+
@hint('pair `course.title`')
153+
@hint('pair `student.name`')
151154

152155
+ Use `flatten` to put all data into a single array. Set `students` to the result.
153156
@test('1/06/03-concat')
@@ -157,6 +160,7 @@ var doubleArray = courses.map(function(course) {
157160
var students = doubleArray;
158161
```
159162
))
163+
@hint('call `.flatten()` on `doubleArray`')
160164

161165
+ Use the `suspects` array to `filter` to only "Hack Kerr"'s data
162166
@test('1/06/04-concat')
@@ -178,3 +182,4 @@ var newSuspects = ['Albert Gonzalez', 'Kevin Mitnick'];
178182

179183
`concat` the `newSuspects` onto the `suspects` list.
180184
@test('1/06/05-concat')
185+
@hint('call `suspects.concat()` with `newSuspects`')

‎tutorial/1/07/reduce.md‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ function add(a, b) {
6060
}
6161
6262
// total the numbers using a reduce function
63-
// initialValue defaults to 0
6463
var total = practice.reduce();
6564
```
6665
))
66+
@hint('with only numbers, the initialValue defaults to 0')
67+
@hint('just call `reduce` with `add`')
6768

6869
+ Not all reduce functions are so easy. `reduce` is a little more difficult to master.
6970

@@ -74,14 +75,17 @@ var total = practice.reduce();
7475
7576
var averages = courses.map(function(course) {
7677
var sum = course.students.reduce(function(total, student) {
77-
// calculate score totals here
7878
79-
// set initialValue to 0
79+
8080
});
8181
return Math.round(sum / course.students.length, 0);
8282
});
8383
```
8484
))
85+
@hint('set the initialValue to 0')
86+
@hint('like this: `reduce(function () {}, 0)`')
87+
@hint('return the sum of `student.score` and `total`')
88+
8589

8690
+ `reduce` to an array of suspect scores from the `suspectData` we collected previously.
8791
@test('1/07/03-reduce')
@@ -96,7 +100,6 @@ var suspectScores = suspectData.reduce(function(total, next) {
96100
});
97101
if (index < 0) {
98102
total.push({
99-
// add a new {name: '', scores: [72]} object
100103
101104
102105
});
@@ -109,6 +112,10 @@ var suspectScores = suspectData.reduce(function(total, next) {
109112
110113
```
111114
))
115+
@hint('if the name is new, push an object with name & scores: `{ name: '', scores: [42]}`')
116+
@hint('match for `next.name` & `next.score`')
117+
@hint('you can concat the scores onto an array: `[].concat(next.score)`')
118+
@hint('if the name is already in the list, just add the `next.score`')
112119

113120
+ `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:
114121
```js
@@ -124,7 +131,6 @@ var suspectScores = suspectData.reduce(function(total, next) {
124131
125132
var suspectStats = suspectScores.map(function(suspect) {
126133
// calculate the total difference in scores from the averages
127-
// you may want to third reduce param: index
128134
var difference = suspect.scores.reduce();
129135
130136
return {
@@ -135,6 +141,9 @@ var suspectStats = suspectScores.map(function(suspect) {
135141
});
136142
```
137143
))
144+
@hint('You may want to use a second param: `index`')
145+
@hint('Compare the `suspect.scores[index]` with the `averages[index]`')
146+
@hint('To get a sum, start your `reduce` function at 0')
138147

139148

140149
+ `reduce` down to likely suspect names by filtering with the `isCheater` function.
@@ -149,9 +158,10 @@ function isCheater(suspect) {
149158
}
150159
151160
// reduce down to a string of likely suspects
152-
var likelySuspects = suspectStats.reduce(function() {}, []).join(', ');
161+
var likelySuspects = suspectStats.reduce(function() {}, []);
153162
```
154163
))
164+
@hint('use `.join(', ')`')
155165

156166
+ It looks like we have a likely suspect.
157167
@test('1/07/06-reduce')

0 commit comments

Comments
 (0)
Please sign in to comment.