Skip to content

Commit fa47c70

Browse files
committed
Refactor getIntersection() using Array.filter()
1 parent ca3800a commit fa47c70

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.swp
2+
*.swo

Diff for: libs/array_lib.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,9 @@ const union = function(firstSet, secondSet){
187187

188188
//get Intersection set of two sets
189189
const getIntersection = function(firstSet, secondSet){
190-
let intersectionSet = [];
191-
for(let element of firstSet){
192-
let isPresentInSecondSet = secondSet.includes(element);
193-
if(isPresentInSecondSet){
194-
intersectionSet.push(element);
195-
}
196-
}
190+
let intersectionSet = firstSet.filter(function(element){
191+
return secondSet.includes(element);
192+
});
197193
return unique(intersectionSet);
198194
}
199195

0 commit comments

Comments
 (0)