dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69162d64f96574d9bb629f02 | Challenge 117: Symmetric Difference | 28 | challenge-117 |
--description--
Given two arrays, return a new array containing the symmetric difference of them.
- The symmetric difference between two sets is the set of values that appear in either set, but not both.
- Return the values in the order they first appear in the input arrays.
--hints--
difference([1, 2, 3], [3, 4, 5]) should return [1, 2, 4, 5].
assert.deepEqual(difference([1, 2, 3], [3, 4, 5]), [1, 2, 4, 5]);
difference(["a", "b"], ["c", "b"]) should return ["a", "c"].
assert.deepEqual(difference(["a", "b"], ["c", "b"]), ["a", "c"]);
difference([1, "a", 2], [2, "b", "a"]) should return [1, "b"].
assert.deepEqual(difference([1, "a", 2], [2, "b", "a"]), [1, "b"]);
difference([1, 3, 5, 7, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]) should return [2, 4, 6, 8].
assert.deepEqual(difference([1, 3, 5, 7, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]), [2, 4, 6, 8]);
--seed--
--seed-contents--
function difference(arr1, arr2) {
return arr1;
}
--solutions--
function difference(arr1, arr2) {
const diff = [];
for (const v of arr1) {
if (!diff.includes(v) && !arr2.includes(v)) diff.push(v)
}
for (const v of arr2) {
if (!diff.includes(v) && !arr1.includes(v)) diff.push(v)
}
return diff;
}