curriculum/challenges/english/blocks/lab-unique-sorted-union/a105e963526e7de52b219be9.md
Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
uniteUnique.uniteUnique function should accept two or more arrays as arguments.[1, 2, 4], [2, 3, 5] would have an output of [1, 2, 4, 3, 5].You should have a uniteUnique function.
assert.isFunction(uniteUnique);
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]) should return [1, 3, 2, 5, 4].
assert.deepEqual(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]), [1, 3, 2, 5, 4]);
uniteUnique([1, 2, 3], [5, 2, 1]) should return [1, 2, 3, 5].
assert.deepEqual(uniteUnique([1, 2, 3], [5, 2, 1]), [1, 2, 3, 5]);
uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]) should return [1, 2, 3, 5, 4, 6, 7, 8].
assert.deepEqual(uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]), [
1,
2,
3,
5,
4,
6,
7,
8
]);
uniteUnique([1, 3, 2], [5, 4], [5, 6]) should return [1, 3, 2, 5, 4, 6].
assert.deepEqual(uniteUnique([1, 3, 2], [5, 4], [5, 6]), [1, 3, 2, 5, 4, 6]);
uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1]) should return [1, 3, 2, 5, 4].
assert.deepEqual(uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1]), [1, 3, 2, 5, 4]);
const uniteUnique = (...arrays) => {
return arrays.reduce((a, b) => {
return [
...a,
...b.filter((e, currentIndex) => b.indexOf(e) === currentIndex && a.indexOf(e) === -1)
];
}, []);
};