* 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>
2.1 KiB
2.1 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
a9bd25c716030ec90084d8a1 | 分割数组 | 5 | 16005 | chunky-monkey |
--description--
请编写一个函数,该函数将一个数组(第一个参数)拆分成若干长度为 size
(第二个参数)的子数组,并将它们作为二维数组返回。
--hints--
chunkArrayInGroups(["a", "b", "c", "d"], 2)
应返回 [["a", "b"], ["c", "d"]]
。
assert.deepEqual(chunkArrayInGroups(['a', 'b', 'c', 'd'], 2), [
['a', 'b'],
['c', 'd']
]);
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)
应返回 [[0, 1, 2], [3, 4, 5]]
。
assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3), [
[0, 1, 2],
[3, 4, 5]
]);
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)
应返回 [[0, 1], [2, 3], [4, 5]]
。
assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2), [
[0, 1],
[2, 3],
[4, 5]
]);
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)
应返回 [[0, 1, 2, 3], [4, 5]]
。
assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4), [
[0, 1, 2, 3],
[4, 5]
]);
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3)
应返回 [[0, 1, 2], [3, 4, 5], [6]]
。
assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3), [
[0, 1, 2],
[3, 4, 5],
[6]
]);
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)
应返回 [[0, 1, 2, 3], [4, 5, 6, 7], [8]]
。
assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4), [
[0, 1, 2, 3],
[4, 5, 6, 7],
[8]
]);
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2)
应返回 [[0, 1], [2, 3], [4, 5], [6, 7], [8]]
。
assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2), [
[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8]
]);
--seed--
--seed-contents--
function chunkArrayInGroups(arr, size) {
return arr;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
--solutions--
function chunkArrayInGroups(arr, size) {
let out = [];
for (let i = 0; i < arr.length; i += size) {
out.push(arr.slice(i, i + size));
}
return out;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);