Created
January 20, 2022 08:05
-
-
Save Stefanacef/8c29874da9e2e7309eee12de687df80c to your computer and use it in GitHub Desktop.
Find Intersection
This file contains 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
Input: ["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"] | |
Output: 1,4,13 | |
function FindIntersection(strArr) { | |
// code goes here | |
const [leftSide,rightSide]=strArr | |
const right=rightSide.split(',').map(el=>el.trim()) | |
const left=leftSide.split(',').map(el=>el.trim()) | |
const filteredArray = left.filter(value => right.includes(value)) | |
return filteredArray.join(',') | |
} | |
// keep this function call here | |
console.log(FindIntersection(readline())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment