* 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>
3.8 KiB
id, title, challengeType, videoUrl, dashedName
id | title | challengeType | videoUrl | dashedName |
---|---|---|---|---|
a3f503de51cf954ede28891d | 找到对称差异 | 5 | find-the-symmetric-difference |
--description--
创建一个带有两个或更多数组的函数,并返回所提供数组的对称差 ( △
或⊕
)数组。给定两个集合(例如集合A = {1, 2, 3}
并且集合B = {2, 3, 4}
),两个集合的数学术语“对称差异”是在任一集合中的元素集合。两组,但两者都没有( A △ B = C = {1, 4}
)。对于你所采取的每一个额外的对称差异(比如在集合D = {2, 3}
),你应该得到具有两个集合中的任何一个但不是两个集合的元素的集合( C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}
)。结果数组必须仅包含唯一值( 不重复 )。如果卡住,请记得使用Read-Search-Ask 。尝试配对程序。编写自己的代码。
--hints--
sym([1, 2, 3], [5, 2, 1, 4])
应返回[3, 4, 5]
。
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4]), [3, 4, 5]);
sym([1, 2, 3], [5, 2, 1, 4])
应仅包含三个元素。
assert.equal(sym([1, 2, 3], [5, 2, 1, 4]).length, 3);
sym([1, 2, 3, 3], [5, 2, 1, 4])
应该返回[3, 4, 5]
。
assert.sameMembers(sym([1, 2, 3, 3], [5, 2, 1, 4]), [3, 4, 5]);
sym([1, 2, 3, 3], [5, 2, 1, 4])
应仅包含三个元素。
assert.equal(sym([1, 2, 3, 3], [5, 2, 1, 4]).length, 3);
sym([1, 2, 3], [5, 2, 1, 4, 5])
应返回[3, 4, 5]
。
assert.sameMembers(sym([1, 2, 3], [5, 2, 1, 4, 5]), [3, 4, 5]);
sym([1, 2, 3], [5, 2, 1, 4, 5])
应仅包含三个元素。
assert.equal(sym([1, 2, 3], [5, 2, 1, 4, 5]).length, 3);
sym([1, 2, 5], [2, 3, 5], [3, 4, 5])
应该返回[1, 4, 5]
assert.sameMembers(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]), [1, 4, 5]);
sym([1, 2, 5], [2, 3, 5], [3, 4, 5])
应仅包含三个元素。
assert.equal(sym([1, 2, 5], [2, 3, 5], [3, 4, 5]).length, 3);
sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])
应该返回[1, 4, 5]
。
assert.sameMembers(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]), [1, 4, 5]);
sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])
应仅包含三个元素。
assert.equal(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]).length, 3);
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])
应该返回[2, 3, 4, 6, 7]
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])
[2, 3, 4, 6, 7]
。
assert.sameMembers(
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]),
[2, 3, 4, 6, 7]
);
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])
应仅包含五个元素。
assert.equal(
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]).length,
5
);
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])
应该返回[1, 2, 4, 5, 6, 7, 8, 9]
。
assert.sameMembers(
sym(
[3, 3, 3, 2, 5],
[2, 1, 5, 7],
[3, 4, 6, 6],
[1, 2, 3],
[5, 3, 9, 8],
[1]
),
[1, 2, 4, 5, 6, 7, 8, 9]
);
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])
应该只包含八个元素。
assert.equal(
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1])
.length,
8
);
--seed--
--seed-contents--
function sym(args) {
return args;
}
sym([1, 2, 3], [5, 2, 1, 4]);
--solutions--
function sym() {
var arrays = [].slice.call(arguments);
return arrays.reduce(function (symDiff, arr) {
return symDiff.concat(arr).filter(function (val, idx, theArr) {
return theArr.indexOf(val) === idx
&& (symDiff.indexOf(val) === -1 || arr.indexOf(val) === -1);
});
});
}
sym([1, 2, 3], [5, 2, 1, 4]);