-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2P2.html
More file actions
37 lines (32 loc) · 859 Bytes
/
L2P2.html
File metadata and controls
37 lines (32 loc) · 859 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
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript current day and time</title>
<h1>
Program to perform intersection between two arrays using Set <br> intersection contains the elements of array1 that are also in array2 <br>
const array1 = [1, 2, 3, 5, 9]; <br>
const array2 = [1, 3, 5, 8]; <br>
</h1>
</head>
<body>
<script type="text/javascript">
function performIntersection(arr1, arr2) {
// converting into Set
const setA = new Set(arr1);
const setB = new Set(arr2);
let intersectionResult = [];
for (let i of setB) {
if (setA.has(i)) {
intersectionResult.push(i);
}
}
return intersectionResult;
}
const array1 = [1, 2, 3, 5, 9];
const array2 = [1, 3, 5, 8];
const result = performIntersection(array1, array2);
console.log(result);
</script>
</body>
</html>