feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0095583028
commit
ee1e8abd87
@ -3,6 +3,7 @@ id: 595011cba5a81735713873bd
|
||||
title: 每组排名最高
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
dashedName: top-rank-per-group
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -84,5 +85,77 @@ assert.equal(res2[2].length, 1);
|
||||
assert.equal(res3[2][1].name, 'Maze Runner');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const 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' },
|
||||
{ name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' },
|
||||
{ name: 'Claire Buckman', id: 'E39876', salary: 27800, dept: 'D202' },
|
||||
{ name: 'David McClellan', id: 'E04242', salary: 41500, dept: 'D101' },
|
||||
{ name: 'Rich Holcomb', id: 'E01234', salary: 49500, dept: 'D202' },
|
||||
{ name: 'Nathan Adams', id: 'E41298', salary: 21900, dept: 'D050' },
|
||||
{ name: 'Richard Potter', id: 'E43128', salary: 15900, dept: 'D101' },
|
||||
{ name: 'David Motsinger', id: 'E27002', salary: 19250, dept: 'D202' },
|
||||
{ name: 'Tim Sampair', id: 'E03033', salary: 27000, dept: 'D101' },
|
||||
{ name: 'Kim Arlich', id: 'E10001', salary: 57000, dept: 'D190' },
|
||||
{ name: 'Timothy Grove', id: 'E16398', salary: 29900, dept: 'D190' }
|
||||
];
|
||||
|
||||
const res1 = topRankPerGroup(10, testData1, 'dept', 'salary');
|
||||
|
||||
const 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 }
|
||||
];
|
||||
|
||||
const res2 = topRankPerGroup(1, testData2, 'genre', 'rating');
|
||||
const res3 = topRankPerGroup(2, testData2, 'genre', 'rating');
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function topRankPerGroup(n, data, groupName, rankName) {
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
const collectDept = function (arrOfObj, groupName) {
|
||||
const collect = arrOfObj.reduce((rtnObj, obj) => {
|
||||
if (rtnObj[obj[groupName]] === undefined) {
|
||||
rtnObj[obj[groupName]] = [];
|
||||
}
|
||||
rtnObj[obj[groupName]].push(obj);
|
||||
return rtnObj;
|
||||
}, {} // initial value to reduce
|
||||
);
|
||||
|
||||
return Object.keys(collect).sort().map(key => collect[key]);
|
||||
};
|
||||
|
||||
const sortRank = function (arrOfRankArrs, rankName) {
|
||||
return arrOfRankArrs.map(item => item.sort((a, b) => {
|
||||
if (a[rankName] > b[rankName]) { return -1; }
|
||||
if (a[rankName] < b[rankName]) { return 1; }
|
||||
return 0;
|
||||
}));
|
||||
};
|
||||
|
||||
function topRankPerGroup(n, data, groupName, rankName) {
|
||||
if (n < 0) { return; }
|
||||
return sortRank(collectDept(data, groupName),
|
||||
rankName).map(list => list.slice(0, n));
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user