Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Created January 20, 2022 08:05
Show Gist options
  • Save Stefanacef/8c29874da9e2e7309eee12de687df80c to your computer and use it in GitHub Desktop.
Save Stefanacef/8c29874da9e2e7309eee12de687df80c to your computer and use it in GitHub Desktop.
Find Intersection
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