96 lines
4.1 KiB
Markdown
96 lines
4.1 KiB
Markdown
---
|
||
title: Top rank per group
|
||
id: 595011cba5a81735713873bd
|
||
challengeType: 5
|
||
videoUrl: ''
|
||
localeTitle: 每组排名最高
|
||
---
|
||
|
||
## Description
|
||
<section id="description">任务: <p>在每个组中查找排名前N位的数据,其中N作为参数提供。等级和组的名称也作为参数提供。 </p>鉴于以下数据: <pre> [
|
||
{姓名:'Tyler Bennett',id:'E10297',薪水:32000,部门:'D101'},
|
||
{姓名:'John Rappl',id:'E21437',薪水:47000,部门:'D050'},
|
||
{姓名:'George Woltman',id:'E00127',薪水:53500,部门:'D101'},
|
||
{name:'Adam Smith',id:'E63535',薪水:18000,部门:'D202'},
|
||
{姓名:'Claire Buckman',id:'E39876',薪水:27800,部门:'D202'},
|
||
{姓名:'David McClellan',id:'E04242',薪水:41500,部门:'D101'},
|
||
{name:'Rich Holcomb',id:'E01234',薪水:49500,dept:'D202'},
|
||
{姓名:'Nathan Adams',id:'E41298',薪水:21900,部门:'D050'},
|
||
{姓名:'Richard Potter',id:'E43128',薪水:15900,部门:'D101'},
|
||
{姓名:'David Motsinger',id:'E27002',薪水:19250,dept:'D202'},
|
||
{姓名:'Tim Sampair',id:'E03033',薪水:27000,部门:'D101'},
|
||
{姓名:'Kim Arlich',id:'E10001',薪水:57000,部门:'D190'},
|
||
{name:'Timothy Grove',id:'E16398',薪水:29900,部门:'D190'}
|
||
]。
|
||
</pre>通过调用<code>topRankPerGroup(10, data, 'dept', 'salary')</code>可以对每个部门的前10名员工进行排名。给出以下数据: <pre> [
|
||
{name:'Friday 13th',类型:'恐怖',评分:9.9},
|
||
{姓名:“榆树街上的梦魇”,类型:'恐怖',等级:5.7},
|
||
{name:'Titanic',类型:'drama',评分:7.3},
|
||
{name:'Maze Runner',类型:'scifi',评级:7.1},
|
||
{name:'Blade runner',类型:'scifi',评分:8.9}
|
||
]。
|
||
</pre>通过调用<code>topRankPerGroup(1, data, 'genre', 'rating')</code>可以在每个类型中对排名最高的电影进行排名</section>
|
||
|
||
## Instructions
|
||
<section id="instructions">
|
||
</section>
|
||
|
||
## Tests
|
||
<section id='tests'>
|
||
|
||
```yml
|
||
tests:
|
||
- text: <code>topRankPerGroup</code>是一个函数。
|
||
testString: 'assert(typeof topRankPerGroup === "function", "<code>topRankPerGroup</code> is a function.");'
|
||
- text: <code>topRankPerGroup</code>在负n值上返回undefined。
|
||
testString: 'assert(typeof topRankPerGroup(-1, []) === "undefined", "<code>topRankPerGroup</code> returns undefined on negative n values.");'
|
||
- text: 第一部门必须是D050
|
||
testString: 'assert.equal(res1[0][0].dept, "D050", "First department must be D050");'
|
||
- text: 第一部门必须是D050
|
||
testString: 'assert.equal(res1[0][1].salary, 21900, "First department must be D050");'
|
||
- text: 最后一个部门必须是D202
|
||
testString: 'assert.equal(res1[3][3].dept, "D202", "The last department must be D202");'
|
||
- text: '<code>topRankPerGroup(1, ...)</code>必须仅返回每组的排名最高的结果。'
|
||
testString: 'assert.equal(res2[2].length, 1, "<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.");'
|
||
- text: '<code>topRankPerGroup(1, ...)</code>必须仅返回每组的排名最高的结果。'
|
||
testString: 'assert.equal(res3[2][1].name, "Maze Runner", "<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.");'
|
||
|
||
```
|
||
|
||
</section>
|
||
|
||
## Challenge Seed
|
||
<section id='challengeSeed'>
|
||
|
||
<div id='js-seed'>
|
||
|
||
```js
|
||
function topRankPerGroup(n, data, groupName, rankName) {
|
||
// Good luck!
|
||
return true;
|
||
}
|
||
|
||
```
|
||
|
||
</div>
|
||
|
||
|
||
### After Test
|
||
<div id='js-teardown'>
|
||
|
||
```js
|
||
console.info('after the test');
|
||
```
|
||
|
||
</div>
|
||
|
||
</section>
|
||
|
||
## Solution
|
||
<section id='solution'>
|
||
|
||
```js
|
||
// solution required
|
||
```
|
||
</section>
|