var itemA = [1, 2, 3, 3]
var itemB = [3, 3, 2]
var crossArr = [];
var countArr = [];
itemA.forEach((e) => {
if (itemB.includes(e)) {
!crossArr.includes(e) && crossArr.push(e);
}
})
function count(item, total = 0, index = 0, arr = itemA.concat(itemB)) {
if (arr.indexOf(item, index) >= 0) {
total++;
index = arr.indexOf(item, index) + 1;
return count(item, total, index)
}
return total;
}
countArr = crossArr.map(e => {
return count(e)
})
var maxCount = Math.max(...countArr);
var maxCountIndex = countArr.indexOf(maxCount)
var maxValue = crossArr[maxCountIndex]
console.log(`${maxValue}重复最多次,共${maxCount}次`)