Created
March 8, 2020 01:33
-
-
Save thillain/e457183ede920b76dd24f195394f3084 to your computer and use it in GitHub Desktop.
Find Intersection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findIntersection(strArr) { | |
let result = []; | |
if (Array.isArray(strArr)) { | |
let arg1 = strArr[0].split(",").map(elem => elem.trim()); | |
let arg2 = strArr[1].split(",").map(elem => elem.trim()); | |
arg1.filter(a => { | |
if (arg2.includes(a)) { | |
result.push(a.trim()); | |
} | |
}); | |
} | |
if (result.length > 0) { | |
return result.join(","); | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment