fix(learn): make tests and test descriptions more explicit (#41281)
* fix: make tests and descriptions more explicit
* fix: add example to description
* fix: replace pre tags with markdown
* fix: move test data to seed code for convenience
* fix: correct grammar from review
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
* Revert "fix: move test data to seed code for convenience"
This reverts commit 7a9c4723d6
.
* fix: small corrections
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
pull/41456/head
parent
42a811ea83
commit
9669e39b85
|
@ -12,7 +12,8 @@ Find the top `n` ranked data in each group, where `n` is provided as a parameter
|
|||
|
||||
Given the following data:
|
||||
|
||||
<pre>[
|
||||
```js
|
||||
testData1 = [
|
||||
{ name: 'Tyler Bennett', id: 'E10297', salary: 32000, dept: 'D101' },
|
||||
{ name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050' },
|
||||
{ name: 'George Woltman', id: 'E00127', salary: 53500, dept: 'D101' },
|
||||
|
@ -27,29 +28,52 @@ Given the following data:
|
|||
{ name: 'Kim Arlich', id: 'E10001', salary: 57000, dept: 'D190' },
|
||||
{ name: 'Timothy Grove', id: 'E16398', salary: 29900, dept: 'D190' }
|
||||
];
|
||||
</pre>
|
||||
```
|
||||
|
||||
one could rank top 10 employees in each department by calling
|
||||
One could rank top 10 employees in each department by calling:
|
||||
|
||||
`topRankPerGroup(10, data, 'dept', 'salary')`
|
||||
`topRankPerGroup(10, testData1, 'dept', 'salary')`
|
||||
|
||||
Given the following data:
|
||||
|
||||
<pre>[
|
||||
```js
|
||||
testData2 = [
|
||||
{ name: 'Friday 13th', genre: 'horror', rating: 9.9 },
|
||||
{ name: "Nightmare on Elm's Street", genre: 'horror', rating: 5.7 },
|
||||
{ name: 'Titanic', genre: 'drama', rating: 7.3 },
|
||||
{ name: 'Maze Runner', genre: 'scifi', rating: 7.1 },
|
||||
{ name: 'Blade runner', genre: 'scifi', rating: 8.9 }
|
||||
];
|
||||
</pre>
|
||||
```
|
||||
|
||||
one could rank the top-rated movie in each genre by calling
|
||||
One could rank the top-rated movie in each genre by calling:
|
||||
|
||||
`topRankPerGroup(1, data, 'genre', 'rating')`
|
||||
`topRankPerGroup(1, testData2, 'genre', 'rating')`
|
||||
|
||||
The function should return an array with an array for each group containing the top `n` objects.
|
||||
|
||||
For example, given data:
|
||||
|
||||
```js
|
||||
[
|
||||
{ name: 'Claire Buckman', id: 'E39876', salary: 27800, dept: 'D101' },
|
||||
{ name: 'Rich Holcomb', id: 'E01234', salary: 49500, dept: 'D050' },
|
||||
{ name: 'David Motsinger', id: 'E27002', salary: 19250, dept: 'D050' },
|
||||
{ name: 'Tim Sampair', id: 'E03033', salary: 27000, dept: 'D101' },
|
||||
{ name: 'Kim Arlich', id: 'E10001', salary: 57000, dept: 'D050' },
|
||||
{ name: 'Timothy Grove', id: 'E16398', salary: 29900, dept: 'D101' }
|
||||
];
|
||||
```
|
||||
|
||||
Top two ranking employees in each department by salary would be:
|
||||
|
||||
```js
|
||||
[ [ { name: 'Kim Arlich', id: 'E10001', salary: 57000, dept: 'D050' },
|
||||
{ name: 'Rich Holcomb', id: 'E01234', salary: 49500, dept: 'D050' } ],
|
||||
[ { name: 'Timothy Grove', id: 'E16398', salary: 29900, dept: 'D101' },
|
||||
{ name: 'Claire Buckman', id: 'E39876', salary: 27800, dept: 'D101' } ] ]
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
`topRankPerGroup` should be a function.
|
||||
|
@ -64,22 +88,16 @@ assert(typeof topRankPerGroup === 'function');
|
|||
assert(typeof topRankPerGroup(-1, []) === 'undefined');
|
||||
```
|
||||
|
||||
First department should be D050
|
||||
For `topRankPerGroup(10, testData1, 'dept', 'salary')`, the first result in the first group should be `{ name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050'}`.
|
||||
|
||||
```js
|
||||
assert.equal(res1[0][0].dept, 'D050');
|
||||
assert.deepEqual(res1[0][0], { name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050'});
|
||||
```
|
||||
|
||||
First department should be D050
|
||||
For `topRankPerGroup(10, testData1, 'dept', 'salary')`, the last result in the last group should be `{ name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' }`.
|
||||
|
||||
```js
|
||||
assert.equal(res1[0][1].salary, 21900);
|
||||
```
|
||||
|
||||
The last department should be D202
|
||||
|
||||
```js
|
||||
assert.equal(res1[3][3].dept, 'D202');
|
||||
assert.deepEqual(res1[3][3], { name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' });
|
||||
```
|
||||
|
||||
`topRankPerGroup(1, ...)` should return only top ranking result per group.
|
||||
|
@ -88,7 +106,7 @@ assert.equal(res1[3][3].dept, 'D202');
|
|||
assert.equal(res2[2].length, 1);
|
||||
```
|
||||
|
||||
`topRankPerGroup(1, ...)` should return only top ranking result per group.
|
||||
`topRankPerGroup(2, ...)` should return two ranking results per group.
|
||||
|
||||
```js
|
||||
assert.equal(res3[2][1].name, 'Maze Runner');
|
||||
|
|
Loading…
Reference in New Issue