Skip to content

Commit 5468711

Browse files
committed
tutorial progress
1 parent 68c09d5 commit 5468711

File tree

11 files changed

+146
-61
lines changed

11 files changed

+146
-61
lines changed

coderoad.json

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,46 @@
2828
"1/01/02-filter"
2929
],
3030
"actions": [
31-
"insert('// note: data is set as a global\nvar myData = data.filter // call filter condition here\n')"
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')",
32+
"insert('// call filter condition here\nvar myData = data.filter();\n\n')"
3233
]
3334
},
3435
{
35-
"description": "Set `var myBest` to your scores, excluding any grades that are \"D\" or \"F\".",
36+
"description": "Write a filter condition called `isGoodGrade` that will filter out any \"D\" or \"F\" grades.",
3637
"tests": [
3738
"1/01/03-filter"
3839
],
3940
"actions": [
40-
"insert('var myBest = myData.filter // filter out \"D\"'s and \"F\"'s here\n')"
41+
"insert('// return true if student \"grade\" is not a \"D\" or \"F\"\nfunction isGoodGrade() {\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')"
4151
]
4252
}
4353
]
4454
},
4555
{
4656
"title": "Sort",
47-
"description": "Array -> sorted Array"
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.",
59+
"tasks": [
60+
{
61+
"description": "Write a sort condition function called `sortByScore` that can sort your data by score.",
62+
"tests": [
63+
"1/02/01-sort"
64+
],
65+
"actions": [
66+
"open('02-sort.js')",
67+
"set('function sortByScore(a, b) {\n // it should return -1 a's score is bigger than b's\n\n // it should return 1 if a's score is less than b's\n\n // it should return 0 if a has the same score as b\n\n}\n')"
68+
]
69+
}
70+
]
4871
},
4972
{
5073
"title": "Map",

tutorial/1/01/01-filter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var expect = require('chai').expect;
22
var path = require('path');
33
var loadJS = require('../../common/loadJS').default;
44
if (!global.data) {
5-
global.data = JSON.parse(JSON.stringify(require('./data.json')));
5+
global.data = JSON.parse(JSON.stringify(require('../../data/students.json')));
66
}
77
loadJS('01-filter.js');
88

tutorial/1/01/02-filter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var expect = require('chai').expect;
22
var path = require('path');
33
var loadJS = require('../../common/loadJS').default;
44
if (!global.data) {
5-
global.data = JSON.parse(JSON.stringify(require('./data.json')));
5+
global.data = JSON.parse(JSON.stringify(require('../../data/students.json')));
66
}
77
loadJS('01-filter.js');
88

tutorial/1/01/03-filter.spec.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@ var expect = require('chai').expect;
22
var path = require('path');
33
var loadJS = require('../../common/loadJS').default;
44
if (!global.data) {
5-
global.data = JSON.parse(JSON.stringify(require('./data.json')));
5+
global.data = JSON.parse(JSON.stringify(require('../../data/students.json')));
66
}
77
loadJS('01-filter.js');
88

9-
describe('var myBest', function() {
9+
describe('isGoodGrade', function() {
1010

1111
it('doesn\'t exist', function() {
12-
expect(myBest).to.not.be.undefined;
12+
expect(isGoodGrade).to.not.be.undefined;
1313
});
1414

15-
it('doesn\'t output an array', function() {
16-
expect(myBest).to.be.an('array');
15+
it('isn\'t a Function', function() {
16+
expect(isGoodGrade).to.be.a('function');
1717
});
1818

19-
it('doesn\'t output exactly ten items', function() {
20-
expect(myBest).to.have.length(7);
19+
it('doesn\'t have any params', function() {
20+
expect(isGoodGrade.length).to.equal(1);
2121
});
2222

23-
it('isn\'t the right filtered data for "Ada Lovelace"', function() {
24-
var values = [91, 88, 81, 73, 93, 82, 88];
25-
myBestVals = myBest.map(function(x) {
26-
return x.score;
27-
});
28-
values.forEach(function(value) {
29-
expect(myBestVals).contains(value);
30-
});
23+
it('doesn\'t return true when an items name matches "Ada Lovelace"', function() {
24+
var test = [{
25+
grade: 'A'
26+
}, {
27+
grade: 'D'
28+
}, {
29+
grade: 'F'
30+
}, {
31+
grade: 'B'
32+
}];
33+
expect(test.filter(isGoodGrade)).to.deep.equal([{
34+
grade: 'A'
35+
}, {
36+
grade: 'B'
37+
}]);
3138
});
3239

3340
});

tutorial/1/01/04-filter.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var expect = require('chai').expect;
2+
var path = require('path');
3+
var loadJS = require('../../common/loadJS').default;
4+
if (!global.data) {
5+
global.data = JSON.parse(JSON.stringify(require('../../data/students.json')));
6+
}
7+
loadJS('01-filter.js');
8+
9+
describe('var myBest', function() {
10+
11+
it('doesn\'t exist', function() {
12+
expect(myBest).to.not.be.undefined;
13+
});
14+
15+
it('doesn\'t output an array', function() {
16+
expect(myBest).to.be.an('array');
17+
});
18+
19+
it('doesn\'t output exactly ten items', function() {
20+
expect(myBest).to.have.length(7);
21+
});
22+
23+
it('isn\'t the right filtered data for "Ada Lovelace"', function() {
24+
var values = [91, 88, 81, 73, 93, 82, 88];
25+
myBestVals = myBest.map(function(x) {
26+
return x.score;
27+
});
28+
values.forEach(function(value) {
29+
expect(myBestVals).contains(value);
30+
});
31+
});
32+
33+
});

tutorial/1/01/filter.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,44 @@ function isAda(x) {
6565
@test('1/01/02-filter')
6666
@action(insert(
6767
```
68-
// note: data is set as a global
69-
var myData = data.filter // call filter condition here
68+
/**
69+
* Data is set as a global. Example:
70+
* [{
71+
* "course": "Relational Databases",
72+
* "instructor": "Sean Quentin Lewis",
73+
* "name": "Ada Lovelace",
74+
* "score": 91,
75+
* "grade": "A"
76+
* },
77+
* ...
78+
* ]
79+
*/
80+
```
81+
))
82+
@action(insert(
83+
```
84+
// call filter condition here
85+
var myData = data.filter();
86+
7087
```))
7188
89+
+ Write a filter condition called `isGoodGrade` that will filter out any "D" or "F" grades.
90+
@test('1/01/03-filter')
91+
@action(insert(
92+
```
93+
// return true if student "grade" is not a "D" or "F"
94+
function isGoodGrade() {
95+
96+
}
97+
```
98+
))
99+
72100
+ Set `var myBest` to your scores, excluding any grades that are "D" or "F".
73101
74-
@test('1/01/03-filter')
102+
@test('1/01/04-filter')
75103
@action(insert(
76104
```
77-
var myBest = myData.filter // filter out "D"'s and "F"'s here
105+
// filter out "D"'s and "F"'s here
106+
var myBest = myData.filter();
107+
78108
```))

tutorial/1/02/01-sort.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var expect = require('chai').expect;
2+
var path = require('path');
3+
var loadJS = require('../../common/loadJS').default;
4+
if (!global.data) {
5+
global.data = JSON.parse(JSON.stringify(require('../../data/students.json')));
6+
}
7+
loadJS('02-sort.js');
8+
9+
describe('', function () {});

tutorial/1/02/sort.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
### Sort
22
Array -> sorted Array
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.
5+
6+
We can use the array method `sort` to arrange our data. Let's see how it works.
7+
8+
+ Write a sort condition function called `sortByScore` that can sort your data by score.
9+
@test('1/02/01-sort')
10+
@action(open('02-sort.js'))
11+
@action(set(
12+
```
13+
function sortByScore(a, b) {
14+
// it should return -1 a's score is bigger than b's
15+
16+
// it should return 1 if a's score is less than b's
17+
18+
// it should return 0 if a has the same score as b
19+
20+
}
21+
```))

tutorial/data/students.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
File renamed without changes.

tutorial/data/students2.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)