2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a9bd25c716030ec90084d8a1
|
|
|
|
challengeType: 5
|
|
|
|
videoUrl: ''
|
2020-10-01 17:54:21 +02:00
|
|
|
title: 矮胖的猴子
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-06-30 01:51:26 -07:00
|
|
|
<section id="description">编写一个函数,将数组(第一个参数)拆分为<code>size</code>的长度(第二个参数),并将它们作为二维数组返回。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。编写自己的代码。 </section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id="instructions">
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
|
|
|
- text: '<code>chunkArrayInGroups(["a", "b", "c", "d"], 2)</code>应返回<code>[["a", "b"], ["c", "d"]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups(["a", "b", "c", "d"], 2), [["a", "b"], ["c", "d"]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)</code>应返回<code>[[0, 1, 2], [3, 4, 5]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3), [[0, 1, 2], [3, 4, 5]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)</code>应返回<code>[[0, 1], [2, 3], [4, 5]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2), [[0, 1], [2, 3], [4, 5]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)</code>应该返回<code>[[0, 1, 2, 3], [4, 5]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4), [[0, 1, 2, 3], [4, 5]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3)</code>应该返回<code>[[0, 1, 2], [3, 4, 5], [6]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3), [[0, 1, 2], [3, 4, 5], [6]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)</code>应返回<code>[[0, 1, 2, 3], [4, 5, 6, 7], [8]]</code> <code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)</code> <code>[[0, 1, 2, 3], [4, 5, 6, 7], [8]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4), [[0, 1, 2, 3], [4, 5, 6, 7], [8]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2)</code>应返回<code>[[0, 1], [2, 3], [4, 5], [6, 7], [8]]</code> 。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2), [[0, 1], [2, 3], [4, 5], [6, 7], [8]]);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function chunkArrayInGroups(arr, size) {
|
|
|
|
// Break it up.
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunkArrayInGroups(["a", "b", "c", "d"], 2);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
|
|
/section>
|