Skip to content

Commit fca2f2d

Browse files
committed
Find column element check using hashtable
1 parent 9567e47 commit fca2f2d

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/javascript/algorithms/array/verifyCommonElements.js

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function isCommonElementExistsWithObject(arr1, arr2) {
2+
let obj = {};
3+
for (let i =0; i < arr1.length; i++) {
4+
obj[arr1[i]] = true;
5+
}
6+
for (let j =0; j < arr2.length; j++) {
7+
if(obj[arr2[j]]) return true;
8+
}
9+
return false;
10+
}
11+
12+
function isCommonElementExistsWithMap(arr1, arr2) {
13+
let map = new Map();
14+
for (let i of arr1) {
15+
map.set(i, true);
16+
}
17+
for (let j of arr2) {
18+
if(map.get(j)) return true;
19+
}
20+
return false;
21+
}
22+
23+
const arr1 = [10, 43, 9, 7];
24+
const arr2 = [17, 33, 10, 2];
25+
isCommonElementExistsWithObject(arr1, arr2);
26+
isCommonElementExistsWithMap(arr1, arr2);

0 commit comments

Comments
 (0)