xxxxxxxxxx
function FindIntersection(strArr) {
const data = strArr.join('.').split('.')
const firstArr = data[0].split(',')
const lastArr = data[1].split(',')
const srings = []
firstArr.forEach((val) => {
let data = lastArr.indexOf(val)
if(data !== -1) {
srings.push(val.trim())
}
})
return srings.join(',')
}
xxxxxxxxxx
function FindIntersection(strArr) {
let firstIndex = strArr[0].split(',').sort((a, c) => a + c)
let secondIndex = strArr[1].split(',').sort((a, c) => a + c)
let data = []
secondIndex.forEach((val, i) => {
if (firstIndex.indexOf(val) !== -1) {
data.push(val)
}
})
if (data.length === firstIndex.length) return false
return data.join(',')
}
console.log(FindIntersection(['1, 3, 4, 7, 13', '1, 2, 4, 13, 15']))