Skip to content

Commit 6ba1597

Browse files
committed
complete step 9 tasks and tests
1 parent 386c707 commit 6ba1597

File tree

6 files changed

+10
-23
lines changed

6 files changed

+10
-23
lines changed

coderoad.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@
531531
]
532532
},
533533
{
534-
"description": "add a `SORT_BY_POPULARITY` case that returns `pokemon.sort();`",
534+
"description": "back in \"src/pokemon/index.js\", add a `SORT_BY_POPULARITY` case that returns `pokemon.sort();`",
535535
"tests": [
536536
"09/05"
537537
],
@@ -548,7 +548,7 @@
548548
"Try this: `case SORT_BY_POPULARITY: return pokemon.sort(sortByVotes)`"
549549
],
550550
"actions": [
551-
"insert('\nfunction sortByVotes(a, b) {\n switch(true) {\n case a.votes > b.votes:\n return 1;\n case a.votes < b.votes:\n return -1;\n default: return 0;\n }\n}\n\n')"
551+
"insert('\nfunction sortByVotes(a, b) {\n switch(true) {\n case a.votes < b.votes:\n return 1;\n case a.votes > b.votes:\n return -1;\n default: return 0;\n }\n}\n\n')"
552552
]
553553
},
554554
{

tutorial/09/04.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('04 sortByPopularity action', () => {
22

33
it('should be dispatched', () => {
4-
const regex = /store.dispatch\s?\(\s?sortByPopularity\(\s?\)\s?)/;
4+
const regex = /store.dispatch\s?\(\s?sortByPopularity\(\s?\)\s?\)/m;
55
expect(indexJs.__text__).to.match(regex);
66
});
77

tutorial/09/05.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ describe('05 pokemon reducer', () => {
33
const pokemon = pokemonIndexJs.__get__('pokemon');
44

55
it('has a SORT_BY_POPULARITY case', () => {
6-
const regex = /case\s?+SORT_BY_POPULARITY/;
6+
const regex = /case\s+?SORT_BY_POPULARITY\s?:/;
77
expect(pokemon.toString()).to.match(regex);
88
});
99

1010
it('case SORT_BY_POPULARITY should sort pokemon', () => {
11-
const regex = /pokemon.sort(.*)/;
11+
const regex = /case\s+?SORT_BY_POPULARITY\s?:\n?\s+?return\s+?pokemon.sort\(/;
1212
expect(pokemon.toString()).to.match(regex);
1313
});
1414

tutorial/09/06.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe('06 sortByVotes function', () => {
22

3-
if (Number(process.env.TASK_POSITION) <= 5) {
3+
// if (Number(process.env.TASK_POSITION) <= 5) {
44

55
const sortByVotes = pokemonIndexJs.__get__('sortByVotes');
66

@@ -18,19 +18,11 @@ describe('06 sortByVotes function', () => {
1818
expect(pokemon.toString()).to.match(regex);
1919
});
2020

21-
it('should sort a list of objects with vote', () => {
22-
const list = [{votes: 3}, {votes: 1}, {votes: 2}];
23-
expect(list.sort(sortByVotes)).to.not.deep.equal(list);
24-
});
25-
2621
it('should sort a list in descending order', () => {
2722
const list = [{votes: 3}, {votes: 1}, {votes: 2}];
2823
const expected = [{votes: 3}, {votes: 2}, {votes: 1}];
2924
expect(list.sort(sortByVotes)).to.deep.equal(expected);
3025
});
3126

32-
} else {
33-
it('passes', () => expect(true).to.be(true));
34-
}
35-
27+
// }
3628
});

tutorial/09/07.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ describe('07 sortByKey function', () => {
1414
expect(sortByKey).to.have.length(1);
1515
});
1616

17-
it('should sort a list of objects by a key', () => {
18-
const list = [{a: 3}, {a: 1}, {a: 2}];
19-
expect(list.sort(sortByKey('a'))).to.not.deep.equal(list);
20-
});
21-
2217
it('should sort a list in descending order', () => {
2318
const list = [{a: 3}, {a: 1}, {a: 2}];
2419
const expected = [{a: 3}, {a: 2}, {a: 1}];

tutorial/09/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Sort pokemon by votes
3333
@hint('use `store.dispatch(actionCreator)`')
3434
@hint('Try this: `store.dispatch(sortByPopularity())`')
3535

36-
+ add a `SORT_BY_POPULARITY` case that returns `pokemon.sort();`
36+
+ back in "src/pokemon/index.js", add a `SORT_BY_POPULARITY` case that returns `pokemon.sort();`
3737
@test('09/05')
3838
@hint('Try this: `case SORT_BY_POPULARITY: return pokemon.sort()`')
3939

@@ -45,9 +45,9 @@ Sort pokemon by votes
4545
4646
function sortByVotes(a, b) {
4747
switch(true) {
48-
case a.votes > b.votes:
49-
return 1;
5048
case a.votes < b.votes:
49+
return 1;
50+
case a.votes > b.votes:
5151
return -1;
5252
default: return 0;
5353
}

0 commit comments

Comments
 (0)