-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL9MergingSets.js
More file actions
31 lines (26 loc) · 844 Bytes
/
L9MergingSets.js
File metadata and controls
31 lines (26 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const mergeSet = (arr1, arr2) => {
let zipArr = [];
for (let num of arr1) {
if (!zipArr.includes(num) && !isNaN(num) && num !== null) {
zipArr.push(num);
// If zipArr does not contain num, num is a number
// and num doesn't equal null then it will push
// num to zipArr.
}
}
for (let num of arr2) {
if (!zipArr.includes(num) && !isNaN(num) && num !== null) {
zipArr.push(num);
// Same as lines 3-10 but for arr2.
}
}
return zipArr;
};
console.log(mergeSet([1,2,3], [3,4,5]));
// Merging Sets
// Write a function, mergeSet, that merges two arrays and removes all duplicate elements.
// Example:
// let array1 = [1, 2, 3];
// let array2 = [3, 4, 5];
// console.log(mergeSet(array1, array2));
// // [1, 2, 3, 4, 5]